"use client";
import { jsx, jsxs } from "react/jsx-runtime";
import { Package, Tag as TagIcon } from "lucide-react";
import { useT } from "@open-mercato/shared/lib/i18n/context";
import { KeyValueList, RecordCardShell, TagRow, statusToTagVariant } from "./RecordCardShell.js";
function formatPrice(price, currency) {
  if (price === null || price === void 0 || price === "") return null;
  const value = typeof price === "number" ? price : Number(price);
  if (!Number.isFinite(value)) {
    return typeof price === "string" ? price : 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 ProductCard(props) {
  const t = useT();
  const status = props.status ? { label: props.status, variant: statusToTagVariant(props.status) } : null;
  const price = formatPrice(props.price, props.currency);
  const leading = props.imageUrl ? /* @__PURE__ */ jsx("div", { className: "relative size-12 overflow-hidden rounded-md border border-border bg-muted", children: /* @__PURE__ */ jsx(
    "img",
    {
      src: props.imageUrl,
      alt: props.name,
      className: "size-full object-cover",
      loading: "lazy"
    }
  ) }) : /* @__PURE__ */ jsx("div", { className: "flex size-12 items-center justify-center rounded-md border border-border bg-muted text-muted-foreground", "aria-hidden": true, children: /* @__PURE__ */ jsx(Package, { className: "size-5" }) });
  const items = [
    props.sku ? { label: t("ai_assistant.chat.records.fields.sku", "SKU"), value: /* @__PURE__ */ jsx("span", { className: "font-mono text-[11px]", children: props.sku }) } : null,
    price ? { label: t("ai_assistant.chat.records.fields.price", "Price"), value: /* @__PURE__ */ jsx("span", { className: "font-medium", children: price }) } : null,
    props.category ? { label: t("ai_assistant.chat.records.fields.category", "Category"), value: props.category } : null
  ].filter(Boolean);
  return /* @__PURE__ */ jsx(
    RecordCardShell,
    {
      kindLabel: t("ai_assistant.chat.records.kinds.product", "Product"),
      kindIcon: /* @__PURE__ */ jsx(Package, { className: "size-4", "aria-hidden": true }),
      leading,
      title: props.name,
      subtitle: [props.sku, price].filter(Boolean).join(" \u2022 ") || void 0,
      status,
      href: props.href,
      id: props.id,
      className: props.className,
      dataKind: "product",
      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 ProductCard_default = ProductCard;
export {
  Package,
  ProductCard,
  TagIcon,
  ProductCard_default as default
};
//# sourceMappingURL=ProductCard.js.map
