"use client";
import { jsx, jsxs } from "react/jsx-runtime";
import { Briefcase, Building2, CalendarDays, CircleDollarSign, User } from "lucide-react";
import { useT } from "@open-mercato/shared/lib/i18n/context";
import { KeyValueList, RecordCardShell, TagRow, statusToTagVariant } from "./RecordCardShell.js";
function formatAmount(amount, currency) {
  if (amount === null || amount === void 0 || amount === "") return null;
  const value = typeof amount === "number" ? amount : Number(amount);
  if (!Number.isFinite(value)) {
    return typeof amount === "string" ? amount : null;
  }
  const code = currency && currency.length === 3 ? currency.toUpperCase() : void 0;
  try {
    if (code) {
      return new Intl.NumberFormat(void 0, { style: "currency", currency: code }).format(value);
    }
  } catch {
  }
  const formatted = new Intl.NumberFormat().format(value);
  return code ? `${formatted} ${code}` : formatted;
}
function formatDate(value) {
  if (!value) return null;
  const d = new Date(value);
  if (Number.isNaN(d.getTime())) return value;
  return d.toLocaleDateString(void 0, { year: "numeric", month: "short", day: "numeric" });
}
function DealCard(props) {
  const t = useT();
  const status = props.status ? { label: props.status, variant: statusToTagVariant(props.status) } : null;
  const stage = props.stage && props.stage !== props.status ? props.stage : null;
  const amount = formatAmount(props.amount, props.currency);
  const closeDate = formatDate(props.closeDate);
  const items = [
    stage ? { label: t("ai_assistant.chat.records.fields.stage", "Stage"), value: stage } : null,
    amount ? { label: t("ai_assistant.chat.records.fields.amount", "Amount"), value: /* @__PURE__ */ jsx("span", { className: "font-medium", children: amount }) } : null,
    closeDate ? { label: t("ai_assistant.chat.records.fields.close", "Close"), value: closeDate } : null,
    props.companyName ? { label: t("ai_assistant.chat.records.fields.company", "Company"), value: props.companyName } : null,
    props.personName ? { label: t("ai_assistant.chat.records.fields.contact", "Contact"), value: props.personName } : null,
    props.ownerName ? { label: t("ai_assistant.chat.records.fields.owner", "Owner"), value: props.ownerName } : null
  ].filter(Boolean);
  const subtitleParts = [];
  if (props.companyName) subtitleParts.push(props.companyName);
  if (props.personName && !props.companyName) subtitleParts.push(props.personName);
  if (amount) subtitleParts.push(amount);
  return /* @__PURE__ */ jsx(
    RecordCardShell,
    {
      kindLabel: t("ai_assistant.chat.records.kinds.deal", "Deal"),
      kindIcon: /* @__PURE__ */ jsx(Briefcase, { className: "size-4", "aria-hidden": true }),
      title: props.title,
      subtitle: subtitleParts.join(" \u2022 "),
      status,
      href: props.href,
      id: props.id,
      className: props.className,
      dataKind: "deal",
      children: /* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
        /* @__PURE__ */ jsx(KeyValueList, { items }),
        props.description ? /* @__PURE__ */ jsx("p", { className: "line-clamp-2 text-muted-foreground", children: props.description }) : null,
        props.tags && props.tags.length > 0 ? /* @__PURE__ */ jsx(TagRow, { tags: props.tags }) : null
      ] })
    }
  );
}
var DealCard_default = DealCard;
export {
  Briefcase,
  Building2,
  CalendarDays,
  CircleDollarSign,
  DealCard,
  User,
  DealCard_default as default
};
//# sourceMappingURL=DealCard.js.map
