"use client";

import Link from "next/link";

type CleanupCard = {
  label: string;
  count: number;
  detail: string;
  cta: string;
  tone: "urgent" | "watch" | "calm";
  href?: string;
  onClick?: () => void;
  disabled?: boolean;
};

const toneClasses: Record<CleanupCard["tone"], string> = {
  urgent: "border-red-200 bg-red-50 text-red-700",
  watch: "border-amber-200 bg-amber-50 text-amber-700",
  calm: "border-emerald-200 bg-emerald-50 text-emerald-700",
};

export function DispatchSelectedWorkCleanupAcceleration({
  cards,
  summary,
}: {
  cards: CleanupCard[];
  summary: string[];
}) {
  return (
    <section className="rounded-2xl border bg-white p-4 shadow-sm">
      <div className="flex flex-col gap-3 lg:flex-row lg:items-start lg:justify-between">
        <div>
          <div className="text-sm font-semibold text-gray-900">Dispatch selected-work cleanup acceleration</div>
          <div className="text-xs text-gray-500">Trim or clear noisy selected work fast so the next action stays focused on the loads that still deserve active follow-through.</div>
        </div>
        <div className="flex flex-wrap gap-2">
          {summary.length ? summary.map((item) => (
            <span key={item} className="rounded-full bg-gray-100 px-2.5 py-1 text-xs font-medium text-gray-700">{item}</span>
          )) : <span className="rounded-full bg-gray-100 px-2.5 py-1 text-xs font-medium text-gray-700">Cleanup ready</span>}
        </div>
      </div>

      <div className="mt-4 grid gap-3 xl:grid-cols-4">
        {cards.map((card) => (
          <div key={card.label} className="rounded-xl border p-4">
            <div className="flex items-start justify-between gap-3">
              <div>
                <div className="text-sm font-semibold text-gray-900">{card.label}</div>
                <div className="mt-2 text-xs text-gray-600">{card.detail}</div>
              </div>
              <span className={`rounded-full border px-2.5 py-1 text-xs font-semibold ${toneClasses[card.tone]}`}>{card.count}</span>
            </div>
            <div className="mt-4">
              {card.href ? (
                <Link href={card.href} className={`inline-flex items-center rounded-full border bg-white px-3 py-1.5 text-xs font-medium text-gray-700 hover:bg-gray-50 ${card.disabled ? "pointer-events-none opacity-50" : ""}`}>
                  {card.cta}
                </Link>
              ) : (
                <button type="button" onClick={card.onClick} disabled={card.disabled} className="inline-flex items-center rounded-full border bg-white px-3 py-1.5 text-xs font-medium text-gray-700 hover:bg-gray-50 disabled:opacity-50">
                  {card.cta}
                </button>
              )}
            </div>
          </div>
        ))}
      </div>
    </section>
  );
}
