import { A as e, K as t, P as n, bt as r, f as i, ot as a, t as o } from "../../dist-DgSmYkuV.js";
import { fluxl as s } from "../../editors/languages/fluxl.js";
import { yaral as c } from "../../editors/languages/yaral.js";
import { yara as l } from "../../editors/languages/yara.js";
import { t as u } from "../../json-D8YcUjFo.js";
import { t as d } from "../../sql-BTWxpluA.js";
import { t as f } from "../../yaml-BAVAG9c4.js";
import { a as p, i as m, n as h, o as g, r as _, t as v } from "../../shell-CH7FHBJf.js";
import { t as y } from "../../utils-B7XIe3qq.js";
import { t as b } from "../../check-CybgTpDT.js";
import { t as x } from "../../copy-Hv8btfHH.js";
import * as S from "react";
import { jsx as C, jsxs as w } from "react/jsx-runtime";
//#region src/react/primitives/code-viewer.tsx
var T = o.define([
	{
		tag: n.keyword,
		color: "var(--cmm-editor-keyword, #7c3aed)"
	},
	{
		tag: n.operator,
		color: "var(--cmm-editor-operator, #0891b2)"
	},
	{
		tag: [n.string, n.special(n.string)],
		color: "var(--cmm-editor-string, #059669)"
	},
	{
		tag: n.number,
		color: "var(--cmm-editor-number, #d97706)"
	},
	{
		tag: n.comment,
		color: "var(--cmm-editor-comment, #6b7280)",
		fontStyle: "italic"
	},
	{
		tag: n.variableName,
		color: "var(--cmm-editor-variable, #1e40af)"
	},
	{
		tag: [n.function(n.variableName)],
		color: "var(--cmm-editor-function, #2563eb)"
	},
	{
		tag: n.typeName,
		color: "var(--cmm-editor-type, #0891b2)"
	},
	{
		tag: n.propertyName,
		color: "var(--cmm-editor-property, #7c3aed)"
	},
	{
		tag: n.bool,
		color: "var(--cmm-editor-atom, #d97706)"
	},
	{
		tag: n.null,
		color: "var(--cmm-editor-atom, #d97706)"
	},
	{
		tag: n.atom,
		color: "var(--cmm-editor-atom, #d97706)"
	},
	{
		tag: n.meta,
		color: "var(--cmm-editor-meta, #6b7280)"
	},
	{
		tag: n.labelName,
		color: "var(--cmm-editor-label, #2563eb)"
	},
	{
		tag: n.namespace,
		color: "var(--cmm-editor-namespace, #0891b2)"
	},
	{
		tag: n.regexp,
		color: "var(--cmm-editor-regexp, #dc2626)"
	},
	{
		tag: n.bracket,
		color: "var(--cmm-editor-bracket, #6b7280)"
	},
	{
		tag: n.punctuation,
		color: "var(--cmm-editor-punctuation, #6b7280)"
	},
	{
		tag: n.tagName,
		color: "var(--cmm-editor-tag, #dc2626)"
	},
	{
		tag: n.attributeName,
		color: "var(--cmm-editor-attribute, #d97706)"
	}
]), E = t.theme({
	"&": {
		fontSize: "13px",
		backgroundColor: "transparent",
		color: "var(--cmm-text-primary, #e2e8f0)"
	},
	"&.cm-focused": { outline: "none" },
	".cm-content": {
		padding: "0",
		caretColor: "transparent",
		fontFamily: "'JetBrains Mono', 'Fira Code', 'Cascadia Code', Consolas, monospace"
	},
	".cm-cursor": { display: "none" },
	".cm-gutters": {
		backgroundColor: "transparent",
		color: "var(--cmm-text-muted, #64748b)",
		borderRight: "1px solid var(--cmm-border, rgba(255,255,255,0.1))",
		fontFamily: "'JetBrains Mono', 'Fira Code', 'Cascadia Code', Consolas, monospace",
		fontSize: "12px",
		minWidth: "3em"
	},
	".cm-activeLineGutter": { backgroundColor: "transparent" },
	".cm-activeLine": { backgroundColor: "transparent" },
	".cm-line": { padding: "0 8px" },
	".cm-scroller": { overflow: "auto" },
	"&.cm-focused .cm-selectionBackground, .cm-selectionBackground": { backgroundColor: "var(--cmm-editor-selection, rgba(59, 130, 246, 0.2))" }
});
function D(e) {
	switch (e.toLowerCase()) {
		case "fluxl":
		case "flux-l": return s();
		case "sql": return d();
		case "yaral":
		case "yara-l":
		case "yara_l": return c();
		case "yara":
		case "yara-x": return l();
		case "json": return u();
		case "yaml":
		case "yml": return f();
		case "python":
		case "py": return g();
		case "javascript":
		case "js":
		case "jsx": return m();
		case "typescript":
		case "ts":
		case "tsx": return p();
		case "rust":
		case "rs": return _();
		case "markdown":
		case "md": return h();
		case "bash":
		case "sh":
		case "shell":
		case "zsh": return v();
		case "sigma": return f();
		case "suricata":
		case "snort": return [];
		default: return [];
	}
}
function O({ className: n, code: o, language: s = "", showLineNumbers: c = !0, showCopyButton: l = !0, languageLabel: u, maxHeight: d, wordWrap: f = !1, ...p }) {
	let m = S.useRef(null), h = S.useRef(null), [g, _] = S.useState(!1), v = S.useRef(null);
	S.useEffect(() => {
		if (!m.current) return;
		h.current &&= (h.current.destroy(), null);
		let n = [
			r.readOnly.of(!0),
			t.editable.of(!1),
			E,
			e(T),
			e(i, { fallback: !0 })
		];
		c && n.push(a()), f && n.push(t.lineWrapping);
		let l = D(s);
		return l && n.push(l), h.current = new t({
			state: r.create({
				doc: o,
				extensions: n
			}),
			parent: m.current
		}), () => {
			h.current &&= (h.current.destroy(), null);
		};
	}, [
		o,
		s,
		c,
		f
	]);
	let O = S.useCallback(() => {
		navigator.clipboard.writeText(o).then(() => {
			_(!0), v.current !== null && clearTimeout(v.current), v.current = setTimeout(() => {
				_(!1), v.current = null;
			}, 2e3);
		});
	}, [o]);
	S.useEffect(() => () => {
		v.current !== null && clearTimeout(v.current);
	}, []);
	let k = u ?? s ?? "";
	return /* @__PURE__ */ w("div", {
		"data-slot": "code-viewer",
		className: y("overflow-hidden rounded-xl border border-border-glass bg-surface-secondary/50 backdrop-blur-[20px]", n),
		...p,
		children: [(k || l) && /* @__PURE__ */ w("div", {
			className: "flex items-center justify-between border-b border-border-glass px-4 py-2",
			children: [/* @__PURE__ */ C("span", {
				className: "text-xs font-medium text-foreground-muted",
				children: k
			}), l && /* @__PURE__ */ w("button", {
				type: "button",
				"aria-label": "Copy code",
				onClick: O,
				className: y("inline-flex items-center gap-1.5 rounded-lg px-2 py-1 text-[11px] font-medium transition-colors", g ? "text-accent-emerald" : "text-foreground-secondary hover:bg-glass-hover hover:text-foreground"),
				children: [C(g ? b : x, { className: "size-3.5" }), g ? "Copied!" : "Copy"]
			})]
		}), /* @__PURE__ */ C("div", {
			ref: m,
			className: "code-viewer-cm",
			style: d ? {
				maxHeight: d,
				overflow: "auto"
			} : void 0
		})]
	});
}
O.displayName = "CodeViewer";
//#endregion
export { O as CodeViewer };

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