"use client";
import { jsx as M } from "react/jsx-runtime";
import { cn as k } from "../../../lib/utils.js";
import * as r from "react";
import { u as z } from "../../../useStableCallback-CudqoENs.js";
import { u as w, w as G } from "../../../useRenderElement-DNB2vtF1.js";
import { c as J, u as Q, C as X, a as F, t as Y, b as Z } from "../../../useCollapsiblePanel-9pDlDh3R.js";
import { t as A, a as ee } from "../../../useOpenChangeComplete-DkeH9FGJ.js";
import { a as te } from "../../../useButton-JYPKQKj4.js";
import { u as R } from "../../../useIsoLayoutEffect-DpJo20by.js";
const U = {
  ...J,
  ...A
}, V = /* @__PURE__ */ r.forwardRef(function(n, p) {
  const {
    render: m,
    className: o,
    defaultOpen: a = !1,
    disabled: g = !1,
    onOpenChange: s,
    open: h,
    ...u
  } = n, d = z(s), e = Q({
    open: h,
    defaultOpen: a,
    onOpenChange: d,
    disabled: g
  }), l = r.useMemo(() => ({
    open: e.open,
    disabled: e.disabled,
    transitionStatus: e.transitionStatus
  }), [e.open, e.disabled, e.transitionStatus]), c = r.useMemo(() => ({
    ...e,
    onOpenChange: d,
    state: l
  }), [e, d, l]), i = w("div", n, {
    state: l,
    ref: p,
    props: u,
    stateAttributesMapping: U
  });
  return /* @__PURE__ */ M(X.Provider, {
    value: c,
    children: i
  });
});
process.env.NODE_ENV !== "production" && (V.displayName = "CollapsibleRoot");
const ne = {
  ...Y,
  ...A
}, I = /* @__PURE__ */ r.forwardRef(function(n, p) {
  const {
    panelId: m,
    open: o,
    handleTrigger: a,
    state: g,
    disabled: s
  } = F(), {
    className: h,
    disabled: u = s,
    id: d,
    render: e,
    nativeButton: l = !0,
    ...c
  } = n, {
    getButtonProps: i,
    buttonRef: N
  } = te({
    disabled: u,
    focusableWhenDisabled: !0,
    native: l
  }), b = r.useMemo(() => ({
    "aria-controls": o ? m : void 0,
    "aria-expanded": o,
    onClick: a
  }), [m, o, a]);
  return w("button", n, {
    state: g,
    ref: [p, N],
    props: [b, c, i],
    stateAttributesMapping: ne
  });
});
process.env.NODE_ENV !== "production" && (I.displayName = "CollapsibleTrigger");
let T = /* @__PURE__ */ (function(t) {
  return t.collapsiblePanelHeight = "--collapsible-panel-height", t.collapsiblePanelWidth = "--collapsible-panel-width", t;
})({});
const _ = /* @__PURE__ */ r.forwardRef(function(n, p) {
  const {
    className: m,
    hiddenUntilFound: o,
    keepMounted: a,
    render: g,
    id: s,
    ...h
  } = n;
  process.env.NODE_ENV !== "production" && R(() => {
    o && a === !1 && G("The `keepMounted={false}` prop on a Collapsible will be ignored when using `hiddenUntilFound` since it requires the Panel to remain mounted even when closed.");
  }, [o, a]);
  const {
    abortControllerRef: u,
    animationTypeRef: d,
    height: e,
    mounted: l,
    onOpenChange: c,
    open: i,
    panelId: N,
    panelRef: b,
    runOnceAnimationsFinish: S,
    setDimensions: x,
    setHiddenUntilFound: E,
    setKeepMounted: D,
    setMounted: B,
    setPanelIdState: P,
    setOpen: H,
    setVisible: W,
    state: y,
    transitionDimensionRef: $,
    visible: j,
    width: O,
    transitionStatus: v
  } = F(), C = o ?? !1, f = a ?? !1;
  R(() => {
    if (s)
      return P(s), () => {
        P(void 0);
      };
  }, [s, P]), R(() => {
    E(C);
  }, [E, C]), R(() => {
    D(f);
  }, [D, f]);
  const {
    props: q
  } = Z({
    abortControllerRef: u,
    animationTypeRef: d,
    externalRef: p,
    height: e,
    hiddenUntilFound: C,
    id: N,
    keepMounted: f,
    mounted: l,
    onOpenChange: c,
    open: i,
    panelRef: b,
    runOnceAnimationsFinish: S,
    setDimensions: x,
    setMounted: B,
    setOpen: H,
    setVisible: W,
    transitionDimensionRef: $,
    visible: j,
    width: O
  });
  ee({
    open: i && v === "idle",
    ref: b,
    onComplete() {
      i && x({
        height: void 0,
        width: void 0
      });
    }
  });
  const K = r.useMemo(() => ({
    ...y,
    transitionStatus: v
  }), [y, v]), L = w("div", n, {
    state: K,
    ref: [p, b],
    props: [q, {
      style: {
        [T.collapsiblePanelHeight]: e === void 0 ? "auto" : `${e}px`,
        [T.collapsiblePanelWidth]: O === void 0 ? "auto" : `${O}px`
      }
    }, h],
    stateAttributesMapping: U
  });
  return f || C || !f && l ? L : null;
});
process.env.NODE_ENV !== "production" && (_.displayName = "CollapsiblePanel");
function ce({ className: t, ...n }) {
  return /* @__PURE__ */ M(
    V,
    {
      className: k(
        "has-[[data-slot=collapsible-trigger][data-disabled]]:opacity-75",
        t
      ),
      "data-slot": "collapsible",
      ...n
    }
  );
}
function be({
  className: t,
  ...n
}) {
  return /* @__PURE__ */ M(
    I,
    {
      className: k(
        "data-disabled:cursor-not-allowed [&[data-disabled]]:hover:bg-transparent",
        t
      ),
      "data-slot": "collapsible-trigger",
      ...n
    }
  );
}
function fe({ ...t }) {
  return /* @__PURE__ */ M(_, { "data-slot": "collapsible-content", ...t });
}
export {
  ce as Collapsible,
  fe as CollapsibleContent,
  be as CollapsibleTrigger
};
