"use client";
import { jsx, jsxs } from "react/jsx-runtime";
import { VisuallyHidden } from "@radix-ui/react-visually-hidden";
import { CircleOff, Clock3, FileWarning, Radar } from "lucide-react";
import { useT } from "@open-mercato/shared/lib/i18n/context";
import { Button } from "@open-mercato/ui/primitives/button";
import { Dialog, DialogContent, DialogTitle } from "@open-mercato/ui/primitives/dialog";
function formatCurrency(value, currency) {
  if (value === null || !Number.isFinite(value)) return "\u2014";
  if (!currency) return value.toLocaleString();
  try {
    return new Intl.NumberFormat(void 0, { style: "currency", currency }).format(value);
  } catch {
    return `${value.toLocaleString()} ${currency}`;
  }
}
function StatCard({
  icon,
  label,
  value
}) {
  return /* @__PURE__ */ jsxs("div", { className: "rounded-2xl border bg-background px-4 py-4", children: [
    /* @__PURE__ */ jsxs("div", { className: "mb-2 flex items-center gap-2 text-xs font-semibold uppercase tracking-[0.14em] text-muted-foreground", children: [
      icon,
      label
    ] }),
    /* @__PURE__ */ jsx("div", { className: "text-xl font-semibold text-foreground", children: value })
  ] });
}
function DealLostSummaryDialog({
  open,
  onClose,
  dealTitle,
  lossNotes,
  stats,
  onBackToPipeline,
  onScheduleFollowUp
}) {
  const t = useT();
  return /* @__PURE__ */ jsx(Dialog, { open, onOpenChange: (nextOpen) => {
    if (!nextOpen) onClose();
  }, children: /* @__PURE__ */ jsxs(DialogContent, { className: "overflow-hidden p-0 sm:max-w-[420px]", children: [
    /* @__PURE__ */ jsx(VisuallyHidden, { children: /* @__PURE__ */ jsx(DialogTitle, { children: t("customers.deals.detail.lost.popupTitle", "Not this round") }) }),
    /* @__PURE__ */ jsxs("div", { className: "overflow-hidden rounded-2xl bg-card", children: [
      /* @__PURE__ */ jsx("div", { className: "px-6 pb-5 pt-6", children: /* @__PURE__ */ jsx("div", { className: "flex h-[200px] items-center justify-center rounded-2xl bg-muted/30 text-foreground", children: /* @__PURE__ */ jsx(CircleOff, { className: "size-24", strokeWidth: 1.5 }) }) }),
      /* @__PURE__ */ jsxs("div", { className: "space-y-5 px-7 pb-7 text-center", children: [
        /* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
          /* @__PURE__ */ jsx("h2", { className: "text-2xl font-bold leading-tight text-foreground", children: t("customers.deals.detail.lost.popupTitle", "Not this round") }),
          /* @__PURE__ */ jsx("p", { className: "text-sm font-medium text-muted-foreground", children: t("customers.deals.detail.lost.popupSubtitle", "Even great teams miss a shot sometimes") })
        ] }),
        /* @__PURE__ */ jsxs("div", { className: "rounded-xl border bg-muted/20 px-4 py-4", children: [
          /* @__PURE__ */ jsx("p", { className: "text-overline font-bold uppercase tracking-[0.16em] text-muted-foreground", children: dealTitle }),
          /* @__PURE__ */ jsx("p", { className: "mt-2 text-2xl font-bold text-muted-foreground", children: stats ? formatCurrency(stats.dealValue, stats.dealCurrency) : "\u2014" }),
          /* @__PURE__ */ jsx("p", { className: "mt-1 text-xs text-muted-foreground", children: t("customers.deals.detail.lost.popupSummary", "Lost \xB7 reason: {{reason}}", {
            reason: stats?.lossReason ?? t("customers.deals.detail.lost.reasonFallback", "Unknown")
          }) })
        ] }),
        /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-3 gap-2", children: [
          /* @__PURE__ */ jsx(
            StatCard,
            {
              icon: /* @__PURE__ */ jsx(Radar, { className: "size-4" }),
              label: t("customers.deals.detail.lost.dealsThisWeek", "Lost this week"),
              value: stats ? String(stats.dealsClosedThisPeriod) : "\u2014"
            }
          ),
          /* @__PURE__ */ jsx(
            StatCard,
            {
              icon: /* @__PURE__ */ jsx(Clock3, { className: "size-4" }),
              label: t("customers.deals.detail.lost.salesCycle", "Sales cycle"),
              value: stats?.salesCycleDays !== null && stats?.salesCycleDays !== void 0 ? `${stats.salesCycleDays}d` : "\u2014"
            }
          ),
          /* @__PURE__ */ jsx(
            StatCard,
            {
              icon: /* @__PURE__ */ jsx(FileWarning, { className: "size-4" }),
              label: t("customers.deals.detail.lost.reason", "Loss reason"),
              value: stats?.lossReason ?? "\u2014"
            }
          )
        ] }),
        lossNotes ? /* @__PURE__ */ jsxs("div", { className: "rounded-xl bg-primary/15 px-4 py-4 text-left", children: [
          /* @__PURE__ */ jsx("div", { className: "text-overline font-bold uppercase tracking-[0.16em] text-foreground", children: t("customers.deals.detail.lost.nextHeading", "What's next") }),
          /* @__PURE__ */ jsx("div", { className: "mt-2 text-xs leading-5 text-muted-foreground", children: lossNotes })
        ] }) : null,
        /* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
          /* @__PURE__ */ jsx(
            Button,
            {
              type: "button",
              className: "w-full",
              onClick: onBackToPipeline ?? onClose,
              children: t("customers.deals.detail.lost.primaryAction", "Back to pipeline")
            }
          ),
          onScheduleFollowUp ? /* @__PURE__ */ jsx(Button, { type: "button", variant: "outline", className: "w-full", onClick: onScheduleFollowUp, children: t("customers.deals.detail.lost.secondaryAction", "Set reminder for Q3") }) : null
        ] })
      ] })
    ] })
  ] }) });
}
export {
  DealLostSummaryDialog
};
//# sourceMappingURL=DealLostSummaryDialog.js.map
