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, { createContext, forwardRef, useContext } from "react";
import { omit } from "../utils-external/index.js";
import { cl } from "../utils/helpers/index.js";
import { useControllableState } from "../utils/hooks/index.js";
import { AccordionContext } from "./AccordionContext.js";
export const AccordionItemContext = createContext(null);
const AccordionItem = forwardRef((_a, ref) => {
    var { children, className, open, defaultOpen = false, onOpenChange } = _a, rest = __rest(_a, ["children", "className", "open", "defaultOpen", "onOpenChange"]);
    const [_open, _setOpen] = useControllableState({
        defaultValue: defaultOpen,
        value: open,
        onChange: onOpenChange,
    });
    const context = useContext(AccordionContext);
    if (!(context === null || context === void 0 ? void 0 : context.mounted)) {
        console.error("<Accordion.Item> has to be used within an <Accordion>");
    }
    return (React.createElement("div", Object.assign({ className: cl("aksel-accordion__item", className, {
            "aksel-accordion__item--open": _open,
        }), "data-expanded": _open, ref: ref }, omit(rest, ["onClick"])),
        React.createElement(AccordionItemContext.Provider, { value: {
                open: _open,
                toggleOpen: () => _setOpen((x) => !x),
            } }, children)));
});
export default AccordionItem;
//# sourceMappingURL=AccordionItem.js.map