import { t as e } from "../../utils-B7XIe3qq.js";
import * as t from "react";
import { Fragment as n, jsx as r, jsxs as i } from "react/jsx-runtime";
//#region src/react/primitives/json-path-browser.tsx
function a(e) {
	return e === null ? "null" : Array.isArray(e) ? "array" : typeof e;
}
function o(e) {
	return e === null ? "null" : typeof e == "string" ? `"${e}"` : typeof e == "number" || typeof e == "boolean" ? String(e) : "";
}
function s(e) {
	return e === null ? "null" : Array.isArray(e) ? `[${e.length}]` : typeof e == "object" ? `{${Object.keys(e).length}}` : typeof e == "string" ? "str" : typeof e == "number" ? "123" : typeof e == "boolean" ? "bool" : typeof e;
}
function c(e) {
	return typeof e == "object" && !!e;
}
function l(e) {
	navigator.clipboard.writeText(e).catch(() => {});
}
function u(e, t, n) {
	return n.length === 0 ? !1 : e.toLowerCase().includes(n) ? !0 : c(t) ? !1 : o(t).toLowerCase().includes(n);
}
function d({ path: t, nodeKey: f, value: p, depth: m, showTypes: h, searchQuery: g, expandedPaths: _, selectedPath: v, onToggle: y, onSelectPath: b }) {
	let x = u(f, p, g);
	if (c(p)) {
		let a = _.has(t), o = Array.isArray(p) ? p.map((e, t) => [String(t), e]) : Object.entries(p);
		return /* @__PURE__ */ i("div", {
			style: { paddingLeft: `${m * 16}px` },
			children: [/* @__PURE__ */ i("div", {
				className: e("flex items-center gap-1 rounded px-1 py-0.5 text-sm", x && "bg-accent-amber/10", v === t && "bg-surface-secondary"),
				children: [
					/* @__PURE__ */ r("button", {
						onClick: () => y(t),
						className: "text-foreground-secondary shrink-0 font-mono text-xs",
						children: a ? "▾" : "▸"
					}),
					f.length > 0 && /* @__PURE__ */ i(n, { children: [/* @__PURE__ */ r("span", {
						className: "text-accent-cyan cursor-pointer font-mono",
						onClick: () => b(t, p),
						children: f
					}), /* @__PURE__ */ r("span", {
						className: "text-foreground-secondary",
						children: ": "
					})] }),
					h && /* @__PURE__ */ r("span", {
						className: e("rounded px-1 py-0.5 font-mono text-[10px]", "bg-surface-secondary text-foreground-secondary"),
						children: s(p)
					})
				]
			}), a && /* @__PURE__ */ r("div", { children: o.map(([e, n]) => /* @__PURE__ */ r(d, {
				path: Array.isArray(p) ? `${t}[${e}]` : `${t}.${e}`,
				nodeKey: e,
				value: n,
				depth: m + 1,
				showTypes: h,
				searchQuery: g,
				expandedPaths: _,
				selectedPath: v,
				onToggle: y,
				onSelectPath: b
			}, e)) })]
		});
	}
	let S = a(p);
	return /* @__PURE__ */ r("div", {
		style: { paddingLeft: `${m * 16}px` },
		children: /* @__PURE__ */ i("div", {
			className: e("flex items-center gap-1 rounded px-1 py-0.5 text-sm", x && "bg-accent-amber/10", v === t && "bg-surface-secondary"),
			children: [
				/* @__PURE__ */ r("span", { className: "w-3.5 shrink-0" }),
				f.length > 0 && /* @__PURE__ */ i(n, { children: [/* @__PURE__ */ r("span", {
					className: "text-accent-cyan cursor-pointer font-mono",
					onClick: () => b(t, p),
					children: f
				}), /* @__PURE__ */ r("span", {
					className: "text-foreground-secondary",
					children: ": "
				})] }),
				/* @__PURE__ */ r("span", {
					className: e("cursor-pointer font-mono", S === "string" && "text-accent-amber", S === "number" && "text-accent-violet", S === "boolean" && "text-accent-rose", S === "null" && "text-foreground-secondary italic"),
					title: "Click to copy value",
					onClick: () => {
						b(t, p), l(typeof p == "object" ? JSON.stringify(p) : String(p));
					},
					children: o(p)
				}),
				h && /* @__PURE__ */ r("span", {
					className: e("rounded px-1 py-0.5 font-mono text-[10px]", "bg-surface-secondary text-foreground-secondary"),
					children: s(p)
				})
			]
		})
	});
}
var f = 100;
function p(e, t, n, r = 0) {
	if (!(r > f || !c(e))) if (n.add(t), Array.isArray(e)) e.forEach((e, i) => p(e, `${t}[${i}]`, n, r + 1));
	else for (let [i, a] of Object.entries(e)) p(a, `${t}.${i}`, n, r + 1);
}
function m(e, t, n, r, i = 0) {
	if (i > f) return !1;
	if (!c(e)) return o(e).toLowerCase().includes(n);
	let a = !1;
	if (Array.isArray(e)) e.forEach((e, o) => {
		m(e, `${t}[${o}]`, n, r, i + 1) && (a = !0);
	});
	else for (let [o, s] of Object.entries(e)) o.toLowerCase().includes(n) && (a = !0), m(s, `${t}.${o}`, n, r, i + 1) && (a = !0);
	return a && r.add(t), a;
}
function h({ data: n, expanded: a = !1, searchable: o = !0, showPath: s = !0, showTypes: c = !0, onSelect: u, className: f, ...h }) {
	let [g, _] = t.useState(() => {
		if (a) {
			let e = /* @__PURE__ */ new Set();
			return p(n, "$", e), e;
		}
		return /* @__PURE__ */ new Set();
	}), [v, y] = t.useState(""), [b, x] = t.useState(""), S = t.useCallback((e) => {
		_((t) => {
			let n = new Set(t);
			return n.has(e) ? n.delete(e) : n.add(e), n;
		});
	}, []), C = t.useCallback((e, t) => {
		y(e), u?.(e, t);
	}, [u]), w = () => {
		let e = /* @__PURE__ */ new Set();
		p(n, "$", e), _(e);
	}, T = () => {
		_(/* @__PURE__ */ new Set());
	}, E = (e) => {
		if (x(e.toLowerCase()), e.length > 0) {
			let t = /* @__PURE__ */ new Set();
			m(n, "$", e.toLowerCase(), t), _(t);
		}
	}, D = () => {
		l(v.length > 0 ? v : "$");
	};
	return /* @__PURE__ */ i("div", {
		"data-slot": "json-path-browser",
		className: e("bg-glass border-border-glass flex flex-col rounded-lg border backdrop-blur-[20px]", f),
		...h,
		children: [
			/* @__PURE__ */ i("div", {
				className: "border-border-glass flex items-center gap-2 border-b px-3 py-2",
				children: [
					/* @__PURE__ */ r("button", {
						onClick: w,
						className: "bg-surface-secondary text-foreground-secondary hover:text-foreground rounded px-2 py-1 text-xs transition-colors",
						children: "Expand All"
					}),
					/* @__PURE__ */ r("button", {
						onClick: T,
						className: "bg-surface-secondary text-foreground-secondary hover:text-foreground rounded px-2 py-1 text-xs transition-colors",
						children: "Collapse All"
					}),
					o && /* @__PURE__ */ r("input", {
						type: "text",
						placeholder: "Search keys or values...",
						className: "bg-surface-secondary text-foreground placeholder:text-foreground-secondary ml-auto rounded px-2 py-1 text-xs outline-none",
						onChange: (e) => E(e.target.value)
					})
				]
			}),
			s && /* @__PURE__ */ r("div", {
				className: "border-border-glass text-foreground-secondary cursor-pointer border-b px-3 py-1.5 font-mono text-xs transition-colors hover:text-foreground",
				title: "Click to copy path",
				onClick: D,
				children: v.length > 0 ? v : "$"
			}),
			/* @__PURE__ */ r("div", {
				className: "flex-1 overflow-auto p-2",
				children: /* @__PURE__ */ r(d, {
					path: "$",
					nodeKey: "",
					value: n,
					depth: 0,
					showTypes: c,
					searchQuery: b,
					expandedPaths: g,
					selectedPath: v,
					onToggle: S,
					onSelectPath: C
				})
			})
		]
	});
}
h.displayName = "JsonPathBrowser";
//#endregion
export { h as JsonPathBrowser };

//# sourceMappingURL=json-path-browser.js.map