"use client";
import { jsx, jsxs } from "react/jsx-runtime";
import { useT } from "@open-mercato/shared/lib/i18n/context";
import {
  getMessageUiComponentRegistry
} from "../../utils/typeUiRegistry.js";
import { getMessageObjectType } from "../../../lib/message-objects-registry.js";
import { toObjectAction } from "../utils.js";
function MessageDetailObjectsSection(props) {
  const t = useT();
  const messageUiRegistry = getMessageUiComponentRegistry();
  if ((props.detail.objects ?? []).length === 0) return null;
  return /* @__PURE__ */ jsxs("section", { className: "space-y-3 pl-4 py-2", children: [
    /* @__PURE__ */ jsx("h2", { className: "text-base font-semibold", children: t("messages.attachedObjects", "Attached objects") }),
    /* @__PURE__ */ jsx("div", { className: "space-y-2", children: (props.detail.objects ?? []).map((item) => {
      const componentKey = `${item.entityModule}:${item.entityType}`;
      const DetailComponent = messageUiRegistry.objectDetailComponents[componentKey] ?? null;
      const objectActions = props.objectActionsByObjectId.get(item.id);
      const objectType = getMessageObjectType(item.entityModule, item.entityType);
      if (DetailComponent) {
        const storedActions = objectActions ? Array.from(objectActions.entries()).map(([actionId, action]) => toObjectAction(actionId, action)) : [];
        const typeDefinitionActions = storedActions.length === 0 ? objectType?.actions ?? [] : [];
        const actions = storedActions.length > 0 ? storedActions : typeDefinitionActions;
        return /* @__PURE__ */ jsx(
          DetailComponent,
          {
            entityId: item.entityId,
            entityModule: item.entityModule,
            entityType: item.entityType,
            snapshot: item.snapshot ?? void 0,
            previewData: item.preview ?? void 0,
            actionRequired: item.actionRequired,
            actionType: item.actionType ?? void 0,
            actionLabel: item.actionLabel ?? void 0,
            actionTaken: props.detail.actionTaken ?? null,
            actionTakenAt: props.detail.actionTakenAt ? new Date(props.detail.actionTakenAt) : null,
            actionTakenByUserId: props.detail.actionTakenByUserId ?? null,
            actions,
            icon: objectType?.icon,
            onAction: async (actionId, payload) => {
              const action = objectActions?.get(actionId);
              if (!action) return;
              await props.onExecuteAction(action, payload);
            }
          },
          item.id
        );
      }
      return null;
    }) })
  ] });
}
export {
  MessageDetailObjectsSection
};
//# sourceMappingURL=objects-panel.js.map
