"use client";
import { jsx, jsxs } from "react/jsx-runtime";
import { Users, ArrowUpRight } from "lucide-react";
import { Badge } from "@open-mercato/ui/primitives/badge";
import { formatCurrency } from "../utils.js";
function ActiveDealWidget({ deals, t }) {
  const topDeal = deals.sort((a, b) => {
    const va = typeof a.valueAmount === "number" ? a.valueAmount : parseFloat(String(a.valueAmount ?? "0"));
    const vb = typeof b.valueAmount === "number" ? b.valueAmount : parseFloat(String(b.valueAmount ?? "0"));
    return vb - va;
  })[0];
  if (!topDeal) {
    return /* @__PURE__ */ jsxs("div", { className: "rounded-lg border bg-card p-5", children: [
      /* @__PURE__ */ jsxs("h3", { className: "flex items-center gap-2 text-sm font-semibold text-foreground", children: [
        /* @__PURE__ */ jsx(Users, { className: "size-4" }),
        t("customers.companies.dashboard.activeDeal", "Active deal")
      ] }),
      /* @__PURE__ */ jsx("p", { className: "mt-3 text-sm text-muted-foreground", children: t("customers.companies.dashboard.noDeals", "No active deals") })
    ] });
  }
  const amount = typeof topDeal.valueAmount === "number" ? topDeal.valueAmount : parseFloat(String(topDeal.valueAmount ?? "0"));
  return /* @__PURE__ */ jsxs("div", { className: "rounded-lg border bg-card p-5", children: [
    /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between", children: [
      /* @__PURE__ */ jsxs("h3", { className: "flex items-center gap-2 text-sm font-semibold text-foreground", children: [
        /* @__PURE__ */ jsx(Users, { className: "size-4" }),
        t("customers.companies.dashboard.activeDeal", "Active deal")
      ] }),
      /* @__PURE__ */ jsx(ArrowUpRight, { className: "size-4 text-muted-foreground" })
    ] }),
    /* @__PURE__ */ jsxs("div", { className: "mt-3", children: [
      /* @__PURE__ */ jsx("p", { className: "font-semibold text-foreground", children: topDeal.title }),
      topDeal.createdAt && /* @__PURE__ */ jsxs("p", { className: "mt-0.5 text-xs text-muted-foreground", children: [
        t("customers.companies.dashboard.created", "Created"),
        " ",
        new Date(topDeal.createdAt).toLocaleDateString()
      ] }),
      topDeal.pipelineStage && /* @__PURE__ */ jsx("div", { className: "mt-2", children: /* @__PURE__ */ jsx(Badge, { variant: "outline", className: "text-xs", children: topDeal.pipelineStage }) }),
      Number.isFinite(amount) && amount > 0 && /* @__PURE__ */ jsxs("p", { className: "mt-2 text-lg font-bold text-foreground", children: [
        formatCurrency(amount, topDeal.valueCurrency),
        /* @__PURE__ */ jsx("span", { className: "ml-1.5 text-xs font-normal text-muted-foreground", children: t("customers.companies.dashboard.potentialValue", "potential value") })
      ] })
    ] })
  ] });
}
export {
  ActiveDealWidget
};
//# sourceMappingURL=ActiveDealWidget.js.map
