"use client";
import { t as e } from "./useControlled-ZBScq72P.js";
import { t } from "./useIsoLayoutEffect-CKOv1bV_.js";
import { d as n, l as r, u as i } from "./useRenderElement-CmuWsiNa.js";
import { t as a } from "./useStableCallback-CqEVb76s.js";
import { S as o, g as s, t as c } from "./createBaseUIEventDetails-ChcQXp54.js";
import { t as l } from "./useBaseUiId-DOm5ACje.js";
import { t as u } from "./useAnimationFrame-xwbX87TY.js";
import { i as d, n as f, o as p, t as m } from "./useOpenChangeComplete-DjMFUwhi.js";
import { l as h } from "./floating-ui.utils.dom-5U5b4xPf.js";
import { t as g } from "./addEventListener-B4Gs94GY.js";
import { t as _ } from "./useValueAsRef-CCU3eUYq.js";
import * as v from "react";
//#region ../../node_modules/.bun/@base-ui+react@1.5.0+f4ada88178b00e6f/node_modules/@base-ui/react/esm/collapsible/root/useCollapsibleRoot.js
function y(t) {
	let { open: n, defaultOpen: r, onOpenChange: i, disabled: s } = t, [u, d] = e({
		controlled: n,
		default: r,
		name: "Collapsible",
		state: "open"
	}), { mounted: f, setMounted: m, transitionStatus: h } = p(u, !0, !0), g = l(), [_, y] = v.useState(), b = _ ?? g, x = a((e) => {
		let t = !u, n = c(o, e.nativeEvent);
		i(t, n), !n.isCanceled && d(t);
	});
	return v.useMemo(() => ({
		disabled: s,
		handleTrigger: x,
		mounted: f,
		open: u,
		panelId: b,
		setMounted: m,
		setOpen: d,
		setPanelIdState: y,
		transitionStatus: h
	}), [
		s,
		x,
		f,
		u,
		b,
		m,
		d,
		y,
		h
	]);
}
//#endregion
//#region ../../node_modules/.bun/@base-ui+react@1.5.0+f4ada88178b00e6f/node_modules/@base-ui/react/esm/collapsible/root/CollapsibleRootContext.js
var b = /*#__PURE__*/ v.createContext(void 0);
process.env.NODE_ENV !== "production" && (b.displayName = "CollapsibleRootContext");
function x() {
	let e = v.useContext(b);
	if (e === void 0) throw Error(process.env.NODE_ENV === "production" ? i(15) : "Base UI: CollapsibleRootContext is missing. Collapsible parts must be placed within <Collapsible.Root>.");
	return e;
}
//#endregion
//#region ../../node_modules/.bun/@base-ui+react@1.5.0+f4ada88178b00e6f/node_modules/@base-ui/react/esm/collapsible/panel/CollapsiblePanelDataAttributes.js
var S = function(e) {
	return e.open = "data-open", e.closed = "data-closed", e[e.startingStyle = d.startingStyle] = "startingStyle", e[e.endingStyle = d.endingStyle] = "endingStyle", e;
}({}), C = /*#__PURE__*/ function(e) {
	return e.panelOpen = "data-panel-open", e;
}({}), w = { [S.open]: "" }, T = { [S.closed]: "" }, E = { open(e) {
	return e ? { [C.panelOpen]: "" } : null;
} }, D = { open(e) {
	return e ? w : T;
} }, O = {
	height: void 0,
	width: void 0
};
function k(e) {
	let { externalRef: n, hiddenUntilFound: i, id: o, keepMounted: l, mounted: d, onOpenChange: p, open: h, setMounted: y, setOpen: b, transitionStatus: x } = e, C = v.useRef(null), w = v.useRef(null), [T, E] = v.useState(O), D = v.useRef(O), k = v.useRef(!1), M = v.useRef(h), F = v.useRef(!1), [I, L] = v.useState(!1), R = v.useRef(null), z = r(n, C), B = _({
		mounted: d,
		open: h
	}), V = f(C, !1, !1), H = !h && !d, U = I ? "idle" : x, W = h && (M.current || F.current), G = !h && d && w.current === "css-animation" && T.height === void 0 && T.width === void 0 ? D.current : T, K = i && H && w.current !== "css-animation", q = a((e, t = !0) => {
		t && (D.current = e), E(e);
	}), J = a(() => {
		R.current?.(), R.current = null;
	}), Y = a((e) => {
		J(), R.current = () => {
			R.current = null, e();
		};
	}), X = a(() => {
		h && d && w.current === "css-animation" && (F.current = !0);
	});
	t(() => {
		!I || x === "starting" || L(!1);
	}, [I, x]), v.useEffect(() => () => {
		X(), J();
	}, [X, J]), t(() => {
		let e = C.current;
		if (!e) return;
		!h && R.current && J();
		let t = j(e, W);
		if (w.current = t, h && x === "idle" && M.current && t === "css-animation") {
			D.current = A(e);
			return;
		}
		if (h && x === "starting") {
			let n = k.current;
			if (k.current = !1, t === "none") {
				q(A(e)), L(!0);
				return;
			}
			if (t === "css-transition") {
				let t = P(e);
				return q(A(e)), n ? (Y(N(e, "transition-duration", "0s")), L(!0), t) : t;
			}
			if (t === "css-animation") {
				if (q(A(e)), !n) {
					N(e, "animation-name", "none")();
					return;
				}
				let t = N(e, "animation-name", "none"), r = N(e, "animation-duration", "0s");
				t(), Y(r), L(!0);
				return;
			}
		}
		if (!h && d && (x === "idle" || x === "starting")) {
			if (t === "none") {
				q(O, !1), y(!1);
				return;
			}
			t === "css-animation" && (M.current = !1, F.current = !1), q(A(e));
			return;
		}
		if (x !== "ending") return;
		if (t === "none") {
			y(!1);
			return;
		}
		let n = A(e);
		if (!((n.height ?? 0) > 0 || (n.width ?? 0) > 0)) {
			y(!1);
			return;
		}
		q(n), t === "css-animation" && N(e, "animation-name", "none")();
	}, [
		d,
		h,
		J,
		q,
		y,
		Y,
		W,
		x
	]), m({
		enabled: h && d && U === "idle",
		open: !0,
		ref: C,
		onComplete() {
			h && q(O, !1);
		}
	}), v.useEffect(() => {
		if (h || !d || U !== "ending" || !C.current) return;
		let e = new AbortController(), t = -1;
		function n() {
			B.current.open || (y(!1), q(O, !1));
		}
		return t = u.request(() => {
			e.signal.aborted || V(n, e.signal);
		}), () => {
			u.cancel(t), e.abort();
		};
	}, [
		B,
		d,
		h,
		U,
		V,
		q,
		y
	]), t(() => {
		let e = C.current;
		!e || !i || !H || e.setAttribute("hidden", "until-found");
	}, [H, i]), v.useEffect(function() {
		let e = C.current;
		if (!e) return;
		function t(e) {
			k.current = !0, b(!0), p(!0, c(s, e));
		}
		return g(e, "beforematch", t);
	}, [p, b]);
	let Z = l || i || d || h;
	return {
		height: G.height,
		props: {
			...K ? { [S.startingStyle]: "" } : void 0,
			hidden: H,
			id: o
		},
		ref: z,
		shouldPreventOpenAnimation: W,
		shouldRender: Z,
		transitionStatus: U,
		width: G.width
	};
}
function A(e) {
	return {
		height: e.scrollHeight,
		width: e.scrollWidth
	};
}
function j(e, t = !1) {
	let r = h(e).getComputedStyle(e), i = (r.animationName.split(",").map((e) => e.trim()).some((e) => e !== "" && e !== "none") || t) && M(r.animationDuration), a = M(r.transitionDuration);
	return i && a ? (process.env.NODE_ENV !== "production" && n("CSS transitions and CSS animations both detected on Collapsible or Accordion panel.", "Only one of either animation type should be used."), "css-transition") : a ? "css-transition" : i ? "css-animation" : "none";
}
function M(e) {
	return e.split(",").map((e) => e.trim()).some((e) => e !== "" && Number.parseFloat(e) > 0);
}
function N(e, t, n) {
	let r = e.style.getPropertyValue(t), i = e.style.getPropertyPriority(t);
	return e.style.setProperty(t, n), () => {
		if (r === "") {
			e.style.removeProperty(t);
			return;
		}
		e.style.setProperty(t, r, i);
	};
}
function P(e) {
	let t = {
		"justify-content": e.style.justifyContent,
		"align-items": e.style.alignItems,
		"align-content": e.style.alignContent,
		"justify-items": e.style.justifyItems
	};
	Object.keys(t).forEach((t) => {
		e.style.setProperty(t, "initial", "important");
	});
	function n() {
		Object.entries(t).forEach(([t, n]) => {
			if (n === "") {
				e.style.removeProperty(t);
				return;
			}
			e.style.setProperty(t, n);
		});
	}
	let r = u.request(n);
	return () => {
		u.cancel(r), n();
	};
}
//#endregion
export { x as a, b as i, D as n, y as o, E as r, k as t };
