import { jsx, jsxs } from "react/jsx-runtime";
import * as React from "react";
import { MarkdownContent } from "@open-mercato/ui/backend/markdown";
import { Button } from "@open-mercato/ui/primitives/button";
function AttachmentContentPreview({
  content,
  maxLength = 480,
  emptyLabel = "No text extracted",
  showMoreLabel = "Show more",
  showLessLabel = "Show less",
  sourceLabel = "Source",
  previewLabel = "Preview"
}) {
  const [expanded, setExpanded] = React.useState(false);
  const [tab, setTab] = React.useState("source");
  const text = (content ?? "").trim();
  const sourceTabId = "attachment-content-preview-tab-source";
  const previewTabId = "attachment-content-preview-tab-preview";
  const sourcePanelId = "attachment-content-preview-panel-source";
  const previewPanelId = "attachment-content-preview-panel-preview";
  if (!text) {
    return /* @__PURE__ */ jsx("div", { className: "text-xs text-muted-foreground italic", children: emptyLabel });
  }
  const shouldTruncate = !expanded && text.length > maxLength;
  const display = tab === "source" && shouldTruncate ? `${text.slice(0, maxLength)}\u2026` : text;
  return /* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
    /* @__PURE__ */ jsx("div", { className: "border-b border-border", children: /* @__PURE__ */ jsxs("nav", { className: "flex items-center gap-4 text-xs", role: "tablist", "aria-label": "Content preview mode", children: [
      /* @__PURE__ */ jsx(
        "button",
        {
          type: "button",
          id: sourceTabId,
          role: "tab",
          "aria-selected": tab === "source",
          "aria-controls": sourcePanelId,
          className: `-mb-px border-b-2 px-0 pb-2 font-medium transition-colors ${tab === "source" ? "border-accent-indigo text-foreground" : "border-transparent text-muted-foreground hover:text-foreground"}`,
          onClick: () => setTab("source"),
          children: sourceLabel
        }
      ),
      /* @__PURE__ */ jsx(
        "button",
        {
          type: "button",
          id: previewTabId,
          role: "tab",
          "aria-selected": tab === "preview",
          "aria-controls": previewPanelId,
          className: `-mb-px border-b-2 px-0 pb-2 font-medium transition-colors ${tab === "preview" ? "border-accent-indigo text-foreground" : "border-transparent text-muted-foreground hover:text-foreground"}`,
          onClick: () => setTab("preview"),
          children: previewLabel
        }
      )
    ] }) }),
    tab === "source" ? /* @__PURE__ */ jsx(
      "div",
      {
        role: "tabpanel",
        id: sourcePanelId,
        "aria-labelledby": sourceTabId,
        "data-testid": "attachment-content-preview",
        className: "whitespace-pre-wrap text-sm text-muted-foreground",
        children: display
      }
    ) : /* @__PURE__ */ jsx(
      "div",
      {
        role: "tabpanel",
        id: previewPanelId,
        "aria-labelledby": previewTabId,
        "data-testid": "markdown-preview",
        children: /* @__PURE__ */ jsx(
          MarkdownContent,
          {
            body: text,
            format: "markdown",
            className: "text-sm text-muted-foreground [&>*]: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"
          }
        )
      }
    ),
    tab === "source" && text.length > maxLength ? /* @__PURE__ */ jsx(
      Button,
      {
        type: "button",
        variant: "ghost",
        size: "sm",
        className: "h-auto px-0 py-1 text-xs",
        onClick: () => setExpanded((prev) => !prev),
        children: expanded ? showLessLabel : showMoreLabel
      }
    ) : null
  ] });
}
export {
  AttachmentContentPreview
};
//# sourceMappingURL=AttachmentContentPreview.js.map
