import Link from "next/link";
"use client";
import useSWR from "swr";

const fetcher = (url: string) => fetch(url).then((r) => r.json());

export function TagFilter({ basePath, current }: { basePath: string; current?: string }) {
  const { data } = useSWR<{ tags: { slug: string; name: string }[] }>("/api/tags", fetcher);
  const tags = data?.tags ?? [];
  return (
    <div style={{ display: "flex", gap: 8, flexWrap: "wrap", marginBottom: 8 }}>
      <Link href={`${basePath}`} style={{ textDecoration: !current ? "underline" : "none" }}>전체</Link>
      {tags.map((t) => (
        <Link key={t.slug} href={`${basePath}?tag=${t.slug}`} style={{ textDecoration: current === t.slug ? "underline" : "none" }}>
          #{t.name}
        </Link>
      ))}
    </div>
  );
}


