import Link from "next/link";
import { listAllGenres } from "@/lib/db/queries";
import { Hash } from "lucide-react";

export const dynamic = "force-dynamic";

export default function GenresPage() {
  const items = listAllGenres();
  return (
    <div className="max-w-[1600px] mx-auto px-6 py-6 fade-in">
      <div className="mb-6">
        <h1 className="text-3xl font-semibold tracking-tight">Genres</h1>
        <p className="text-[var(--color-fg-dim)] mt-1">{items.length} total</p>
      </div>

      {items.length === 0 ? (
        <div className="glass rounded-2xl p-card text-center">
          <Hash className="w-8 h-8 mx-auto text-[var(--color-fg-dim)] mb-label" />
          <p className="text-[var(--color-fg-dim)]">No genres yet.</p>
        </div>
      ) : (
        <div className="flex flex-wrap gap-2">
          {items.map((g) => (
            <Link key={g.id} href={`/genres/${g.slug}`} className="flex items-center gap-2 px-3 py-1.5 rounded-full glass glass-hover text-sm">
              <span className="text-[var(--color-cyan)]">{g.name}</span>
              <span className="text-xs font-mono text-[var(--color-fg-muted)]">{g.count}</span>
            </Link>
          ))}
        </div>
      )}
    </div>
  );
}
