import Link from "next/link";
import type { LoadStateReportItem } from "@/types";

const toneClasses: Record<NonNullable<LoadStateReportItem["tone"]>, string> = {
  default: "bg-gray-100 text-gray-700",
  alert: "bg-red-100 text-red-700",
  warning: "bg-amber-100 text-amber-700",
  good: "bg-emerald-100 text-emerald-700",
};

type ReportActionLink = { href: string; label: string };

export function LoadStateReport({ items, links }: { items: LoadStateReportItem[]; links?: Record<string, ReportActionLink>; }) {
  return (
    <section className="rounded-2xl border bg-white p-4 shadow-sm">
      <div className="flex flex-col gap-1">
        <h3 className="text-sm font-semibold text-gray-900">Load-state reporting</h3>
        <p className="text-xs text-gray-500">Fast count visibility across the full load lifecycle so operators can scan queue shape before diving into record-by-record work.</p>
      </div>

      <div className="mt-4 flex flex-wrap gap-2">
        {items.map((item) => {
          const link = links?.[item.key];
          const classes = `rounded-full px-3 py-1.5 text-xs font-semibold ${toneClasses[item.tone ?? "default"]}`;
          return link ? (
            <Link key={item.key} href={link.href} className={classes}>
              {item.label} {item.count} · {link.label}
            </Link>
          ) : (
            <span key={item.key} className={classes}>
              {item.label} {item.count}
            </span>
          );
        })}
      </div>
    </section>
  );
}
