"use client";
import { jsx, jsxs } from "react/jsx-runtime";
import { useT } from "@open-mercato/shared/lib/i18n/context";
import { MarkdownContent } from "@open-mercato/ui/backend/markdown/MarkdownContent";
import { getMessageUiComponentRegistry } from "../../utils/typeUiRegistry.js";
import { getMessageObjectType } from "../../../lib/message-objects-registry.js";
import { formatDateTime } from "../utils.js";
function MessageDetailThreadSection({ detail }) {
  const t = useT();
  const messageUiRegistry = getMessageUiComponentRegistry();
  if ((detail.thread ?? []).length === 0) return null;
  return /* @__PURE__ */ jsxs("section", { className: "space-y-3 border-l pl-4 py-2", children: [
    /* @__PURE__ */ jsx("h2", { className: "text-base font-semibold", children: t("messages.detail.thread", "Thread") }),
    /* @__PURE__ */ jsx("div", { className: "space-y-3", children: (detail.thread ?? []).map((threadItem) => /* @__PURE__ */ jsxs("article", { className: "rounded border p-3", children: [
      /* @__PURE__ */ jsxs("p", { className: "text-xs text-muted-foreground", children: [
        threadItem.senderName || threadItem.senderEmail || threadItem.senderUserId,
        " \u2022 ",
        formatDateTime(threadItem.sentAt)
      ] }),
      /* @__PURE__ */ jsx("div", { className: "mt-2 max-h-[60vh] overflow-y-auto pr-1", children: /* @__PURE__ */ jsx(
        MarkdownContent,
        {
          body: threadItem.body,
          format: threadItem.bodyFormat ?? "text",
          className: "text-sm whitespace-pre-wrap [&>*]:mb-2 [&>*:last-child]:mb-0 [&_ul]:ml-4 [&_ul]:list-disc [&_ol]:ml-4 [&_ol]:list-decimal [&_code]:rounded [&_code]:bg-muted [&_code]:px-1 [&_code]:py-0.5 [&_pre]:rounded-md [&_pre]:bg-muted [&_pre]:p-3 [&_pre]:text-xs"
        }
      ) }),
      (threadItem.objects ?? []).length > 0 && /* @__PURE__ */ jsxs("div", { className: "mt-3 space-y-2", children: [
        /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground font-medium", children: t("messages.attachedObjects", "Attached objects") }),
        (threadItem.objects ?? []).map((obj) => {
          const componentKey = `${obj.entityModule}:${obj.entityType}`;
          const PreviewComponent = messageUiRegistry.objectPreviewComponents[componentKey] ?? messageUiRegistry.objectPreviewComponents["messages:default"];
          const objectType = getMessageObjectType(obj.entityModule, obj.entityType);
          if (!PreviewComponent) return null;
          return /* @__PURE__ */ jsx("div", { className: "scale-95 origin-left", children: /* @__PURE__ */ jsx(
            PreviewComponent,
            {
              entityId: obj.entityId,
              entityModule: obj.entityModule,
              entityType: obj.entityType,
              snapshot: obj.snapshot ?? void 0,
              previewData: obj.preview ?? void 0,
              actionRequired: obj.actionRequired,
              actionType: obj.actionType ?? void 0,
              actionLabel: obj.actionLabel ?? void 0,
              icon: objectType?.icon
            }
          ) }, obj.id);
        })
      ] })
    ] }, threadItem.id)) })
  ] });
}
export {
  MessageDetailThreadSection
};
//# sourceMappingURL=thread-panel.js.map
