"use client";
import { cn } from "../../lib/utils.js";
import "../ui/button.js";
import { codeToHtml } from "../../node_modules/shiki/dist/bundle-full.js";
import { c } from "react/compiler-runtime";
import { createContext, useContext, useEffect, useRef, useState } from "react";
import { jsx, jsxs } from "react/jsx-runtime";
import { CheckIcon, CopyIcon } from "lucide-react";
var CodeBlockContext = createContext({ code: "" }), lineNumberTransformer = {
	name: "line-numbers",
	line(n, l) {
		n.children.unshift({
			type: "element",
			tagName: "span",
			properties: { className: [
				"inline-block",
				"min-w-10",
				"mr-4",
				"text-right",
				"select-none",
				"text-muted-foreground"
			] },
			children: [{
				type: "text",
				value: String(l)
			}]
		});
	}
};
async function highlightCode(n, u, d = !1) {
	let f = d ? [lineNumberTransformer] : [];
	return await Promise.all([codeToHtml(n, {
		lang: u,
		theme: "one-light",
		transformers: f
	}), codeToHtml(n, {
		lang: u,
		theme: "one-dark-pro",
		transformers: f
	})]);
}
const CodeBlock = (l) => {
	let d = c(33), f, p, m, h, g, _;
	d[0] === l ? (f = d[1], p = d[2], m = d[3], h = d[4], g = d[5], _ = d[6]) : ({code: m, language: h, showLineNumbers: _, className: p, children: f, ...g} = l, d[0] = l, d[1] = f, d[2] = p, d[3] = m, d[4] = h, d[5] = g, d[6] = _);
	let v = _ === void 0 ? !1 : _, [y, b] = useState(""), [x, S] = useState(""), C = useRef(!1), w, T;
	d[7] !== m || d[8] !== h || d[9] !== v ? (w = () => (highlightCode(m, h, v).then((n) => {
		let [l, u] = n;
		C.current ||= (b(l), S(u), !0);
	}), () => {
		C.current = !1;
	}), T = [
		m,
		h,
		v
	], d[7] = m, d[8] = h, d[9] = v, d[10] = w, d[11] = T) : (w = d[10], T = d[11]), useEffect(w, T);
	let E;
	d[12] === m ? E = d[13] : (E = { code: m }, d[12] = m, d[13] = E);
	let D;
	d[14] === p ? D = d[15] : (D = cn("group bg-background text-foreground relative w-full overflow-hidden rounded-md border", p), d[14] = p, d[15] = D);
	let O;
	d[16] === y ? O = d[17] : (O = /* @__PURE__ */ jsx("div", {
		className: "[&>pre]:bg-background! [&>pre]:text-foreground! overflow-hidden dark:hidden [&_code]:font-mono [&_code]:text-sm [&>pre]:m-0 [&>pre]:p-4 [&>pre]:text-sm",
		dangerouslySetInnerHTML: { __html: y }
	}), d[16] = y, d[17] = O);
	let k;
	d[18] === x ? k = d[19] : (k = /* @__PURE__ */ jsx("div", {
		className: "[&>pre]:bg-background! [&>pre]:text-foreground! hidden overflow-hidden dark:block [&_code]:font-mono [&_code]:text-sm [&>pre]:m-0 [&>pre]:p-4 [&>pre]:text-sm",
		dangerouslySetInnerHTML: { __html: x }
	}), d[18] = x, d[19] = k);
	let A;
	d[20] === f ? A = d[21] : (A = f && /* @__PURE__ */ jsx("div", {
		className: "absolute top-2 right-2 flex items-center gap-2",
		children: f
	}), d[20] = f, d[21] = A);
	let j;
	d[22] !== O || d[23] !== k || d[24] !== A ? (j = /* @__PURE__ */ jsxs("div", {
		className: "relative",
		children: [
			O,
			k,
			A
		]
	}), d[22] = O, d[23] = k, d[24] = A, d[25] = j) : j = d[25];
	let M;
	d[26] !== g || d[27] !== D || d[28] !== j ? (M = /* @__PURE__ */ jsx("div", {
		className: D,
		...g,
		children: j
	}), d[26] = g, d[27] = D, d[28] = j, d[29] = M) : M = d[29];
	let N;
	return d[30] !== M || d[31] !== E ? (N = /* @__PURE__ */ jsx(CodeBlockContext.Provider, {
		value: E,
		children: M
	}), d[30] = M, d[31] = E, d[32] = N) : N = d[32], N;
};
export { CodeBlock };
