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

export const dynamic = "force-dynamic";

export default function LabelsPage() {
  const items = listAllLabels();
  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">Labels</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">
          <Tag className="w-8 h-8 mx-auto text-[var(--color-fg-dim)] mb-label" />
          <p className="text-[var(--color-fg-dim)]">No labels yet.</p>
        </div>
      ) : (
        <div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-3">
          {items.map((label) => (
            <Link
              key={label.id}
              href={`/labels/${label.slug}`}
              className="glass glass-hover rounded-xl p-4 flex items-center justify-between gap-3"
            >
              <span className="font-medium truncate">{label.name}</span>
              <span className="text-xs font-mono text-[var(--color-fg-muted)] tabular-nums">{label.count}</span>
            </Link>
          ))}
        </div>
      )}
    </div>
  );
}
