import type { CollectionsRiskItem } from "@/types";

const toneClasses: Record<NonNullable<CollectionsRiskItem["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",
};

export function CollectionsRiskReport({ items }: { items: CollectionsRiskItem[] }) {
  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">Collections-risk reporting</h3>
        <p className="text-xs text-gray-500">Open receivable visibility grouped by collections urgency so operators can see where billing risk is accumulating.</p>
      </div>
      <div className="mt-4 grid gap-3 lg:grid-cols-3">
        {items.map((item) => (
          <div key={item.key} className="rounded-xl border bg-gray-50 p-3">
            <div className="flex items-start justify-between gap-3">
              <div>
                <div className="text-sm font-semibold text-gray-900">{item.label}</div>
                <div className="mt-1 text-xs text-gray-500">{item.detail}</div>
              </div>
              <span className={`rounded-full px-2.5 py-1 text-[11px] font-semibold ${toneClasses[item.tone ?? "default"]}`}>{item.count} loads</span>
            </div>
            <div className="mt-3 text-xl font-semibold text-gray-900">{item.amount}</div>
          </div>
        ))}
      </div>
    </section>
  );
}
