"use client";
import { cn as e } from "../../lib/utils.js";
import "../ui/button.js";
import { codeToHtml as t } from "../../node_modules/shiki/dist/bundle-full.js";
import { createContext as n, useEffect as r, useRef as i, useState as a } from "react";
import { jsx as o, jsxs as s } from "react/jsx-runtime";
import "lucide-react";
//#region src/components/ai-elements/code-block.tsx
var c = n({ code: "" }), l = {
	name: "line-numbers",
	line(e, t) {
		e.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(t)
			}]
		});
	}
};
async function u(e, n, r = !1) {
	let i = r ? [l] : [];
	return await Promise.all([t(e, {
		lang: n,
		theme: "one-light",
		transformers: i
	}), t(e, {
		lang: n,
		theme: "one-dark-pro",
		transformers: i
	})]);
}
var d = ({ code: t, language: n, showLineNumbers: l = !1, className: d, children: f, ...p }) => {
	let [m, h] = a(""), [g, _] = a(""), v = i(!1);
	return r(() => (u(t, n, l).then(([e, t]) => {
		v.current ||= (h(e), _(t), !0);
	}), () => {
		v.current = !1;
	}), [
		t,
		n,
		l
	]), /* @__PURE__ */ o(c.Provider, {
		value: { code: t },
		children: /* @__PURE__ */ o("div", {
			className: e("group bg-background text-foreground relative w-full overflow-hidden rounded-md border", d),
			...p,
			children: /* @__PURE__ */ s("div", {
				className: "relative",
				children: [
					/* @__PURE__ */ o("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: m }
					}),
					/* @__PURE__ */ o("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: g }
					}),
					f && /* @__PURE__ */ o("div", {
						className: "absolute top-2 right-2 flex items-center gap-2",
						children: f
					})
				]
			})
		})
	});
};
//#endregion
export { d as CodeBlock };
