"use client";
import { jsx, jsxs } from "react/jsx-runtime";
import { Link2 } from "lucide-react";
import { useT } from "@open-mercato/shared/lib/i18n/context";
import { Badge } from "@open-mercato/ui/primitives/badge";
import { getMessageObjectType } from "../../lib/message-objects-registry.js";
function readSnapshotLabel(snapshot) {
  if (!snapshot) return null;
  const candidates = ["subject", "title", "name", "label", "id"];
  for (const key of candidates) {
    const value = snapshot[key];
    if (typeof value === "string" && value.trim().length > 0) {
      return value.trim();
    }
  }
  return null;
}
function readSnapshotSubtitle(snapshot) {
  if (!snapshot) return null;
  const candidates = ["type", "status"];
  for (const key of candidates) {
    const value = snapshot[key];
    if (typeof value === "string" && value.trim().length > 0) {
      return value.trim();
    }
  }
  return null;
}
function MessageRecordObjectPreview({
  entityId,
  entityModule,
  entityType,
  snapshot,
  previewData,
  actionRequired,
  actionLabel
}) {
  const t = useT();
  const registeredType = getMessageObjectType(entityModule, entityType);
  const fallbackTitle = t("messages.objectPreview.fallback.title", "Linked object");
  const typeLabel = registeredType ? t(registeredType.labelKey, `${entityModule}:${entityType}`) : `${entityModule}:${entityType}`;
  const title = previewData?.title || readSnapshotLabel(snapshot) || fallbackTitle;
  const subtitle = previewData?.subtitle || readSnapshotSubtitle(snapshot) || t("messages.objectPreview.fallback.subtitle", "{type} \u2022 {id}", { type: typeLabel, id: entityId });
  return /* @__PURE__ */ jsxs("div", { className: "flex items-start gap-3 rounded bg-muted/30 p-3", children: [
    /* @__PURE__ */ jsx(Link2, { className: "mt-0.5 h-4 w-4 text-muted-foreground" }),
    /* @__PURE__ */ jsxs("div", { className: "min-w-0 flex-1 space-y-1", children: [
      /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
        /* @__PURE__ */ jsx("p", { className: "font-medium text-sm", children: title }),
        actionRequired ? /* @__PURE__ */ jsx(Badge, { variant: "secondary", className: "text-xs", children: actionLabel || t("messages.composer.objectActionRequired", "Action required") }) : null
      ] }),
      /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground", title: entityId, children: subtitle }),
      previewData?.status ? /* @__PURE__ */ jsx(Badge, { variant: "outline", className: "text-xs", children: previewData.status }) : null
    ] })
  ] });
}
var MessageRecordObjectPreview_default = MessageRecordObjectPreview;
export {
  MessageRecordObjectPreview,
  MessageRecordObjectPreview_default as default
};
//# sourceMappingURL=MessageRecordObjectPreview.js.map
