import { o as q } from "./rolldown-runtime.js";
import { i as $, t as K } from "./vendor/react.js";
import { t as O } from "./useRenderElement.js";
import { n as L, t as S } from "./useIsoLayoutEffect.js";
import { t as V } from "./useButton.js";
import { a as F, n as z } from "./useTransitionStatus.js";
import { a as D, i as G, n as J, o as Q, r as X, t as Y } from "./useCollapsiblePanel.js";
var s = /* @__PURE__ */ q($()), I = {
  ...J,
  ...F
}, Z = K(), re = /* @__PURE__ */ s.forwardRef(function(t, l) {
  const { render: b, className: r, defaultOpen: p = !1, disabled: f = !1, onOpenChange: n, open: C, style: m, ...g } = t, d = L(n), e = Q({
    open: C,
    defaultOpen: p,
    onOpenChange: d,
    disabled: f
  }), o = s.useMemo(() => ({
    open: e.open,
    disabled: e.disabled,
    transitionStatus: e.transitionStatus
  }), [
    e.open,
    e.disabled,
    e.transitionStatus
  ]), u = s.useMemo(() => ({
    ...e,
    onOpenChange: d,
    state: o
  }), [
    e,
    d,
    o
  ]), a = O("div", t, {
    state: o,
    ref: l,
    props: g,
    stateAttributesMapping: I
  });
  return /* @__PURE__ */ (0, Z.jsx)(G.Provider, {
    value: u,
    children: a
  });
}), ee = {
  ...X,
  ...F
}, pe = /* @__PURE__ */ s.forwardRef(function(t, l) {
  const { panelId: b, open: r, handleTrigger: p, state: f, disabled: n } = D(), { className: C, disabled: m = n, id: g, render: d, nativeButton: e = !0, style: o, ...u } = t, { getButtonProps: a, buttonRef: M } = V({
    disabled: m,
    focusableWhenDisabled: !0,
    native: e
  }), c = s.useMemo(() => ({
    "aria-controls": r ? b : void 0,
    "aria-expanded": r,
    onClick: p
  }), [
    b,
    r,
    p
  ]);
  return O("button", t, {
    state: f,
    ref: [l, M],
    props: [
      c,
      u,
      a
    ],
    stateAttributesMapping: ee
  });
}), A = /* @__PURE__ */ (function(i) {
  return i.collapsiblePanelHeight = "--collapsible-panel-height", i.collapsiblePanelWidth = "--collapsible-panel-width", i;
})({}), de = /* @__PURE__ */ s.forwardRef(function(t, l) {
  const { className: b, hiddenUntilFound: r, keepMounted: p, render: f, id: n, style: C, ...m } = t, { abortControllerRef: g, animationTypeRef: d, height: e, mounted: o, onOpenChange: u, open: a, panelId: M, panelRef: c, runOnceAnimationsFinish: T, setDimensions: _, setHiddenUntilFound: y, setKeepMounted: k, setMounted: U, setPanelIdState: R, setOpen: j, setVisible: B, state: w, transitionDimensionRef: E, visible: H, width: P, transitionStatus: x } = D(), h = r ?? !1, v = p ?? !1;
  S(() => {
    if (n)
      return R(n), () => {
        R(void 0);
      };
  }, [n, R]), S(() => {
    y(h);
  }, [y, h]), S(() => {
    k(v);
  }, [k, v]);
  const { props: N } = Y({
    abortControllerRef: g,
    animationTypeRef: d,
    externalRef: l,
    height: e,
    hiddenUntilFound: h,
    id: M,
    keepMounted: v,
    mounted: o,
    onOpenChange: u,
    open: a,
    panelRef: c,
    runOnceAnimationsFinish: T,
    setDimensions: _,
    setMounted: U,
    setOpen: j,
    setVisible: B,
    transitionDimensionRef: E,
    visible: H,
    width: P
  });
  z({
    open: a && x === "idle",
    ref: c,
    onComplete() {
      a && _({
        height: void 0,
        width: void 0
      });
    }
  });
  const W = O("div", t, {
    state: s.useMemo(() => ({
      ...w,
      transitionStatus: x
    }), [w, x]),
    ref: [l, c],
    props: [
      N,
      { style: {
        [A.collapsiblePanelHeight]: e === void 0 ? "auto" : `${e}px`,
        [A.collapsiblePanelWidth]: P === void 0 ? "auto" : `${P}px`
      } },
      m
    ],
    stateAttributesMapping: I
  });
  return v || h || o ? W : null;
});
export {
  pe as n,
  re as r,
  de as t
};

//# sourceMappingURL=CollapsiblePanel.js.map