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

const toneClasses: Record<NonNullable<QueueOutcomeItem["tone"]>, string> = {
  default: "border-gray-200 bg-white text-gray-900",
  alert: "border-red-200 bg-red-50 text-red-900",
  warning: "border-amber-200 bg-amber-50 text-amber-900",
  good: "border-emerald-200 bg-emerald-50 text-emerald-900",
};

type ReportActionLink = {
  primaryHref: string;
  primaryLabel: string;
  secondaryHref?: string;
  secondaryLabel?: string;
};

export function QueueOutcomeReport({ items, links }: { items: QueueOutcomeItem[]; 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">Queue outcomes</h3>
        <p className="text-xs text-gray-500">The same queue-outcome checkpoints now stay visible across summary, board, and list workflows.</p>
      </div>
      <div className="mt-4 grid gap-3 sm:grid-cols-2 xl:grid-cols-4">
        {items.map((item) => {
          const link = links?.[item.key];
          return (
          <div key={item.key} className={`rounded-xl border p-3 ${toneClasses[item.tone ?? "default"]}`}>
            <div className="text-[11px] font-semibold uppercase tracking-wide opacity-75">{item.label}</div>
            <div className="mt-2 text-2xl font-semibold">{item.count}</div>
            {item.detail ? <div className="mt-1 text-xs opacity-80">{item.detail}</div> : null}
            {link ? (
              <div className="mt-3 flex flex-wrap gap-2">
                <Link href={link.primaryHref} className="rounded-lg border border-current/15 bg-white/80 px-2.5 py-1.5 text-[11px] font-semibold hover:bg-white">
                  {link.primaryLabel}
                </Link>
                {link.secondaryHref && link.secondaryLabel ? (
                  <Link href={link.secondaryHref} className="rounded-lg border border-current/15 bg-white/80 px-2.5 py-1.5 text-[11px] font-semibold hover:bg-white">
                    {link.secondaryLabel}
                  </Link>
                ) : null}
              </div>
            ) : null}
          </div>
        )})}
      </div>
    </section>
  );
}
