"use client";
import { jsx, jsxs } from "react/jsx-runtime";
import { useT } from "@open-mercato/shared/lib/i18n/context";
import {
  AttachmentVisualPreview,
  formatAttachmentFileSize
} from "@open-mercato/ui/backend/detail/AttachmentVisualPreview";
import {
  buildAttachmentImageUrl,
  slugifyAttachmentFileName
} from "@open-mercato/core/modules/attachments/lib/imageUrls";
function MessageDetailAttachmentsSection(props) {
  const t = useT();
  if (props.attachmentsQuery.isLoading) {
    return /* @__PURE__ */ jsxs("section", { className: "space-y-3 pl-4 py-2", children: [
      /* @__PURE__ */ jsx("h2", { className: "text-base font-semibold", children: t("messages.attachedFiles", "Attachments") }),
      /* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground", children: t("messages.loading.attachments", "Loading attachments...") })
    ] });
  }
  if (props.attachmentsQuery.error) {
    return /* @__PURE__ */ jsxs("section", { className: "space-y-3 pl-4 py-2", children: [
      /* @__PURE__ */ jsx("h2", { className: "text-base font-semibold", children: t("messages.attachedFiles", "Attachments") }),
      /* @__PURE__ */ jsx("p", { className: "text-sm text-destructive", children: props.attachmentsQuery.error instanceof Error ? props.attachmentsQuery.error.message : t("messages.errors.loadAttachmentsFailed", "Failed to load attachments.") })
    ] });
  }
  if ((props.attachments ?? []).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.attachedFiles", "Attachments") }),
    /* @__PURE__ */ jsx("div", { className: "space-y-2", children: (props.attachments ?? []).map((attachment) => /* @__PURE__ */ jsxs(
      "a",
      {
        href: attachment.url,
        target: "_blank",
        rel: "noreferrer",
        className: "flex items-center gap-3 rounded px-3 py-2 text-sm hover:bg-muted",
        children: [
          /* @__PURE__ */ jsx(
            AttachmentVisualPreview,
            {
              fileName: attachment.fileName,
              mimeType: attachment.mimeType,
              thumbnailUrl: attachment.mimeType?.toLowerCase().startsWith("image/") ? buildAttachmentImageUrl(attachment.id, {
                width: 120,
                height: 120,
                slug: slugifyAttachmentFileName(attachment.fileName),
                cropType: "cover"
              }) : null,
              className: "h-11 w-11 shrink-0 overflow-hidden rounded",
              iconClassName: "mb-0 h-4 w-4",
              labelClassName: "text-overline"
            }
          ),
          /* @__PURE__ */ jsxs("div", { className: "min-w-0 flex-1", children: [
            /* @__PURE__ */ jsx("p", { className: "truncate", children: attachment.fileName }),
            /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground", children: formatAttachmentFileSize(attachment.fileSize) })
          ] })
        ]
      },
      attachment.id
    )) })
  ] });
}
export {
  MessageDetailAttachmentsSection
};
//# sourceMappingURL=attachments-panel.js.map
