var __rest = (this && this.__rest) || function (s, e) {
    var t = {};
    for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
        t[p] = s[p];
    if (s != null && typeof Object.getOwnPropertySymbols === "function")
        for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
            if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
                t[p[i]] = s[p[i]];
        }
    return t;
};
import React, { forwardRef, useCallback } from "react";
import { useId } from "../../utils-external/index.js";
import { useControllableState } from "../../utils/hooks/index.js";
import CollapsibleContent from "../content/CollapsibleContent.js";
import CollapsibleTrigger from "../trigger/CollapsibleTrigger.js";
import { CollapsibleContextProvider } from "./CollapsibleRoot.context.js";
/**
 * Collapsible is a component that allows you to toggle visibility of content.
 *
 * @example
 * ```jsx
 * <Collapsible>
 *   <Collapsible.Trigger>Trigger</Collapsible.Trigger>
 *   <Collapsible.Content>
 *     Lorem ipsum dolor sit amet consectetur adipisicing elit. Recusandae
 *     corporis maxime aliquam, voluptates nobis numquam, non odit optio
 *     architecto iure laborum possimus! Quibusdam sit ullam, consequatur sunt
 *     tempore optio aliquid!
 *   </Collapsible.Content>
 * </Collapsible>
 * ```
 *
 * @example With asChild
 * ```jsx
 * <Collapsible>
 *   <Collapsible.Trigger asChild>
 *     <Button>Button</Button>
 *   </Collapsible.Trigger>
 *   <Collapsible.Content asChild>
 *     <Box padding="space-16" background="info-soft">
 *       <div>lorem ipsum</div>
 *     </Box>
 *   </Collapsible.Content>
 * </Collapsible>
 * ```
 */
export const Collapsible = forwardRef((_a, ref) => {
    var { children, open, defaultOpen = false, onOpenChange, lazy = false } = _a, rest = __rest(_a, ["children", "open", "defaultOpen", "onOpenChange", "lazy"]);
    const [_open, setOpen] = useControllableState({
        value: open,
        defaultValue: defaultOpen,
        onChange: onOpenChange,
    });
    const internalId = useId();
    const state = _open ? "open" : "closed";
    return (React.createElement(CollapsibleContextProvider, { open: _open, onOpenToggle: useCallback(() => setOpen((prevOpen) => !prevOpen), [setOpen]), contentId: `collapsible-content-${internalId}`, triggerId: `collapsible-trigger-${internalId}`, lazy: lazy, state: state },
        React.createElement("div", Object.assign({ ref: ref, "data-state": state }, rest), children)));
});
Collapsible.Trigger = CollapsibleTrigger;
Collapsible.Content = CollapsibleContent;
export default Collapsible;
export { CollapsibleTrigger, CollapsibleContent };
//# sourceMappingURL=CollapsibleRoot.js.map