'use strict';

var React = require('react');
var index$4 = require('../../../../../@radix-ui_primitive@1.1.2/node_modules/@radix-ui/primitive/dist/index.cjs');
var index = require('../../../../../@radix-ui_react-context@1.1.2_@types_react@18.2.12_react@18.2.0/node_modules/@radix-ui/react-context/dist/index.cjs');
var index$1 = require('../../../../../@radix-ui_react-use-controllable-state@1.2.2_@types_react@18.2.12_react@18.2.0/node_modules/@radix-ui/react-use-controllable-state/dist/index.cjs');
var index$7 = require('../../../../../@radix-ui_react-use-layout-effect@1.1.1_@types_react@18.2.12_react@18.2.0/node_modules/@radix-ui/react-use-layout-effect/dist/index.cjs');
var index$6 = require('../../../../../@radix-ui_react-compose-refs@1.1.2_@types_react@18.2.12_react@18.2.0/node_modules/@radix-ui/react-compose-refs/dist/index.cjs');
var index$3 = require('../../../../../@radix-ui_react-primitive@2.1.3_@types_react-dom@18.0.11_@types_react@18.2.12_react-dom@18.3._wizft3keermhycaiqreghf4gsi/node_modules/@radix-ui/react-primitive/dist/index.cjs');
var index$5 = require('../../../../../@radix-ui_react-presence@1.1.4_@types_react-dom@18.0.11_@types_react@18.2.12_react-dom@18.3.1_react@18.2.0__react@18.2.0/node_modules/@radix-ui/react-presence/dist/index.cjs');
var index$2 = require('../../../../../@radix-ui_react-id@1.1.1_@types_react@18.2.12_react@18.2.0/node_modules/@radix-ui/react-id/dist/index.cjs');
var jsxRuntime = require('../../../../../react@18.2.0/node_modules/react/jsx-runtime.cjs');

function _interopNamespaceDefault(e) {
  var n = Object.create(null);
  if (e) {
    Object.keys(e).forEach(function (k) {
      if (k !== 'default') {
        var d = Object.getOwnPropertyDescriptor(e, k);
        Object.defineProperty(n, k, d.get ? d : {
          enumerable: true,
          get: function () { return e[k]; }
        });
      }
    });
  }
  n.default = e;
  return Object.freeze(n);
}

var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);

var COLLAPSIBLE_NAME = "Collapsible";
var [createCollapsibleContext, createCollapsibleScope] = index.createContextScope(COLLAPSIBLE_NAME);
var [CollapsibleProvider, useCollapsibleContext] = createCollapsibleContext(COLLAPSIBLE_NAME);
var Collapsible = React__namespace.forwardRef(
  (props, forwardedRef) => {
    const {
      __scopeCollapsible,
      open: openProp,
      defaultOpen,
      disabled,
      onOpenChange,
      ...collapsibleProps
    } = props;
    const [open, setOpen] = index$1.useControllableState({
      prop: openProp,
      defaultProp: defaultOpen ?? false,
      onChange: onOpenChange,
      caller: COLLAPSIBLE_NAME
    });
    return /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(
      CollapsibleProvider,
      {
        scope: __scopeCollapsible,
        disabled,
        contentId: index$2.useId(),
        open,
        onOpenToggle: React__namespace.useCallback(() => setOpen((prevOpen) => !prevOpen), [setOpen]),
        children: /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(
          index$3.Primitive.div,
          {
            "data-state": getState(open),
            "data-disabled": disabled ? "" : void 0,
            ...collapsibleProps,
            ref: forwardedRef
          }
        )
      }
    );
  }
);
Collapsible.displayName = COLLAPSIBLE_NAME;
var TRIGGER_NAME = "CollapsibleTrigger";
var CollapsibleTrigger = React__namespace.forwardRef(
  (props, forwardedRef) => {
    const { __scopeCollapsible, ...triggerProps } = props;
    const context = useCollapsibleContext(TRIGGER_NAME, __scopeCollapsible);
    return /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(
      index$3.Primitive.button,
      {
        type: "button",
        "aria-controls": context.contentId,
        "aria-expanded": context.open || false,
        "data-state": getState(context.open),
        "data-disabled": context.disabled ? "" : void 0,
        disabled: context.disabled,
        ...triggerProps,
        ref: forwardedRef,
        onClick: index$4.composeEventHandlers(props.onClick, context.onOpenToggle)
      }
    );
  }
);
CollapsibleTrigger.displayName = TRIGGER_NAME;
var CONTENT_NAME = "CollapsibleContent";
var CollapsibleContent = React__namespace.forwardRef(
  (props, forwardedRef) => {
    const { forceMount, ...contentProps } = props;
    const context = useCollapsibleContext(CONTENT_NAME, props.__scopeCollapsible);
    return /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(index$5.Presence, { present: forceMount || context.open, children: ({ present }) => /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(CollapsibleContentImpl, { ...contentProps, ref: forwardedRef, present }) });
  }
);
CollapsibleContent.displayName = CONTENT_NAME;
var CollapsibleContentImpl = React__namespace.forwardRef((props, forwardedRef) => {
  const { __scopeCollapsible, present, children, ...contentProps } = props;
  const context = useCollapsibleContext(CONTENT_NAME, __scopeCollapsible);
  const [isPresent, setIsPresent] = React__namespace.useState(present);
  const ref = React__namespace.useRef(null);
  const composedRefs = index$6.useComposedRefs(forwardedRef, ref);
  const heightRef = React__namespace.useRef(0);
  const height = heightRef.current;
  const widthRef = React__namespace.useRef(0);
  const width = widthRef.current;
  const isOpen = context.open || isPresent;
  const isMountAnimationPreventedRef = React__namespace.useRef(isOpen);
  const originalStylesRef = React__namespace.useRef(void 0);
  React__namespace.useEffect(() => {
    const rAF = requestAnimationFrame(() => isMountAnimationPreventedRef.current = false);
    return () => cancelAnimationFrame(rAF);
  }, []);
  index$7.useLayoutEffect(() => {
    const node = ref.current;
    if (node) {
      originalStylesRef.current = originalStylesRef.current || {
        transitionDuration: node.style.transitionDuration,
        animationName: node.style.animationName
      };
      node.style.transitionDuration = "0s";
      node.style.animationName = "none";
      const rect = node.getBoundingClientRect();
      heightRef.current = rect.height;
      widthRef.current = rect.width;
      if (!isMountAnimationPreventedRef.current) {
        node.style.transitionDuration = originalStylesRef.current.transitionDuration;
        node.style.animationName = originalStylesRef.current.animationName;
      }
      setIsPresent(present);
    }
  }, [context.open, present]);
  return /* @__PURE__ */ jsxRuntime.jsxRuntimeExports.jsx(
    index$3.Primitive.div,
    {
      "data-state": getState(context.open),
      "data-disabled": context.disabled ? "" : void 0,
      id: context.contentId,
      hidden: !isOpen,
      ...contentProps,
      ref: composedRefs,
      style: {
        [`--radix-collapsible-content-height`]: height ? `${height}px` : void 0,
        [`--radix-collapsible-content-width`]: width ? `${width}px` : void 0,
        ...props.style
      },
      children: isOpen && children
    }
  );
});
function getState(open) {
  return open ? "open" : "closed";
}
var Root = Collapsible;

exports.Collapsible = Collapsible;
exports.CollapsibleContent = CollapsibleContent;
exports.CollapsibleTrigger = CollapsibleTrigger;
exports.Root = Root;
exports.createCollapsibleScope = createCollapsibleScope;
//# sourceMappingURL=index.cjs.map
