import { o as v } from "./rolldown-runtime.js";
import { i as g, t as C } from "./vendor/react.js";
import { t as N } from "./check.js";
import { t as k } from "./copy.js";
import { t as w } from "./Button.js";
import { t as B } from "./dist.js";
import { t as d } from "./utils.js";
import { t as I } from "./lib.js";
var c = /* @__PURE__ */ v(g(), 1), e = C(), A = B("relative overflow-hidden rounded-xl border border-border bg-muted", {
  variants: { size: {
    sm: "text-xs",
    md: "text-sm",
    lg: "text-base"
  } },
  defaultVariants: { size: "md" }
});
function f({ language: t, fileName: o, showCopyButton: a = !0, onCopy: n, copied: r = !1, className: l, actions: s }) {
  return /* @__PURE__ */ (0, e.jsxs)("div", {
    "data-slot": "ai-code-block-header",
    className: d("flex items-center justify-between px-4 py-2 border-b border-border bg-accent", l),
    children: [/* @__PURE__ */ (0, e.jsxs)("div", {
      className: "flex items-center gap-2",
      children: [o && /* @__PURE__ */ (0, e.jsx)("span", {
        className: "text-sm font-medium text-secondary-foreground",
        children: o
      }), t && !o && /* @__PURE__ */ (0, e.jsx)("span", {
        className: "text-xs font-medium text-quaternary-foreground uppercase",
        children: t
      })]
    }), /* @__PURE__ */ (0, e.jsxs)("div", {
      className: "flex items-center gap-2",
      children: [s, a && /* @__PURE__ */ (0, e.jsxs)(w, {
        appearance: "ghost",
        variant: "secondary",
        size: "sm",
        onClick: n,
        "aria-label": r ? "Copied to clipboard" : "Copy code to clipboard",
        className: "h-7 px-2 text-quaternary-foreground hover:text-secondary-foreground transition-colors duration-150 ease-out",
        children: [r ? /* @__PURE__ */ (0, e.jsx)(N, { className: "size-4 text-success delight-bounce-in motion-reduce:animate-none" }) : /* @__PURE__ */ (0, e.jsx)(k, { className: "size-4" }), /* @__PURE__ */ (0, e.jsx)("span", {
          className: "ms-1.5 text-xs",
          children: r ? "Copied!" : "Copy"
        })]
      })]
    })]
  });
}
f.displayName = "AICodeBlockHeader";
function z({ children: t, showLineNumbers: o = !1, startLineNumber: a = 1, className: n }) {
  const r = () => o && typeof t == "string" ? /* @__PURE__ */ (0, e.jsxs)("div", {
    className: "flex",
    children: [/* @__PURE__ */ (0, e.jsx)("div", {
      className: "flex flex-col items-end pe-4 select-none border-e border-border me-4",
      children: t.split(`
`).map((l, s) => /* @__PURE__ */ (0, e.jsx)("span", {
        className: "text-muted-foreground leading-relaxed",
        children: a + s
      }, s))
    }), /* @__PURE__ */ (0, e.jsx)("pre", {
      className: "flex-1 overflow-x-auto",
      children: /* @__PURE__ */ (0, e.jsx)("code", { children: t })
    })]
  }) : /* @__PURE__ */ (0, e.jsx)("pre", {
    className: "overflow-x-auto",
    children: /* @__PURE__ */ (0, e.jsx)("code", { children: t })
  });
  return /* @__PURE__ */ (0, e.jsx)("div", {
    "data-slot": "ai-code-block-content",
    className: d("p-4 font-mono leading-relaxed", n),
    children: r()
  });
}
z.displayName = "AICodeBlockContent";
function q({ code: t, language: o = "plaintext", fileName: a, showHeader: n = !0, showCopyButton: r = !0, showLineNumbers: l = !1, startLineNumber: s = 1, highlightedCode: m, size: p, className: _, headerActions: b }) {
  const h = c.useMemo(() => m ?? I(t), [t, m]), [j, x] = c.useState(!1), u = c.useRef(null), y = c.useCallback(async () => {
    try {
      const i = u.current?.ownerDocument.defaultView;
      if (!i) return;
      await i.navigator.clipboard.writeText(t), x(!0), setTimeout(() => x(!1), 2e3);
    } catch (i) {
      console.error("Failed to copy code:", i);
    }
  }, [t]);
  return /* @__PURE__ */ (0, e.jsxs)("div", {
    ref: u,
    "data-slot": "ai-code-block",
    className: d(A({ size: p }), _),
    children: [n && /* @__PURE__ */ (0, e.jsx)(f, {
      language: o,
      fileName: a,
      showCopyButton: r,
      onCopy: y,
      copied: j,
      actions: b
    }), /* @__PURE__ */ (0, e.jsx)("pre", {
      tabIndex: 0,
      className: d("p-4 overflow-x-auto font-mono leading-relaxed !bg-transparent !m-0 !border-0 !rounded-none", "[&_.sh__line]:block [&_.sh__line]:leading-relaxed", l && ["[&_.sh__line]:[counter-increment:sh-line]", "[&_.sh__line]:before:[content:counter(sh-line)] [&_.sh__line]:before:inline-block [&_.sh__line]:before:w-8 [&_.sh__line]:before:me-4 [&_.sh__line]:before:text-end [&_.sh__line]:before:text-muted-foreground [&_.sh__line]:before:select-none"]),
      style: l ? { counterReset: `sh-line ${s - 1}` } : void 0,
      dangerouslySetInnerHTML: { __html: h }
    })]
  });
}
q.displayName = "AICodeBlock";
export {
  q as t
};

//# sourceMappingURL=AICodeBlock.js.map