import { t as e } from "../../utils-B7XIe3qq.js";
import { t } from "../../check-CybgTpDT.js";
import { t as n } from "../../copy-Hv8btfHH.js";
import * as r from "react";
import { jsx as i, jsxs as a } from "react/jsx-runtime";
//#region src/react/primitives/code-block.tsx
function o({ className: o, code: s, language: c, showLineNumbers: l = !1, showCopyButton: u = !0, maxHeight: d, ...f }) {
	let [p, m] = r.useState(!1), h = r.useRef(null), g = r.useCallback(() => {
		navigator.clipboard.writeText(s).then(() => {
			m(!0), h.current !== null && clearTimeout(h.current), h.current = setTimeout(() => {
				m(!1), h.current = null;
			}, 2e3);
		});
	}, [s]);
	r.useEffect(() => () => {
		h.current !== null && clearTimeout(h.current);
	}, []);
	let _ = s.split("\n");
	return /* @__PURE__ */ a("div", {
		"data-slot": "code-block",
		className: e("overflow-hidden rounded-xl border border-border-glass bg-surface-secondary/50 backdrop-blur-[20px]", o),
		...f,
		children: [(c || u) && /* @__PURE__ */ a("div", {
			className: "flex items-center justify-between border-b border-border-glass px-4 py-2",
			children: [/* @__PURE__ */ i("span", {
				className: "text-xs font-medium text-foreground-muted",
				children: c ?? ""
			}), u && /* @__PURE__ */ a("button", {
				type: "button",
				"aria-label": "Copy code",
				onClick: g,
				className: e("inline-flex items-center gap-1.5 rounded-lg px-2 py-1 text-[11px] font-medium transition-colors", p ? "text-accent-emerald" : "text-foreground-secondary hover:bg-glass-hover hover:text-foreground"),
				children: [i(p ? t : n, { className: "size-3.5" }), p ? "Copied!" : "Copy"]
			})]
		}), /* @__PURE__ */ i("div", {
			className: "overflow-x-auto",
			style: d ? {
				maxHeight: d,
				overflowY: "auto"
			} : void 0,
			children: /* @__PURE__ */ i("pre", {
				className: "p-4 text-[13px] leading-relaxed",
				children: /* @__PURE__ */ i("code", {
					className: "font-mono text-foreground",
					children: l ? _.map((e, t) => /* @__PURE__ */ a("span", {
						className: "table-row",
						children: [
							/* @__PURE__ */ i("span", {
								className: "table-cell select-none pr-4 text-right text-foreground-muted",
								children: t + 1
							}),
							/* @__PURE__ */ i("span", {
								className: "table-cell",
								children: e
							}),
							"\n"
						]
					}, t)) : s
				})
			})
		})]
	});
}
//#endregion
export { o as CodeBlock };

//# sourceMappingURL=code-block.js.map