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, useEffect, useRef } from "react";
import { omit } from "../utils-external/index.js";
import { cl } from "../utils/helpers/index.js";
import { consoleWarning } from "../utils/helpers/consoleWarning.js";
import { useMergeRefs } from "../utils/hooks/index.js";
import AccordionContent from "./AccordionContent.js";
import { AccordionContext } from "./AccordionContext.js";
import AccordionHeader from "./AccordionHeader.js";
import AccordionItem from "./AccordionItem.js";
/**
 * A component that displays collapsible content sections.
 *
 * @see [📝 Documentation](https://aksel.nav.no/komponenter/core/accordion)
 * @see 🏷️ {@link AccordionProps}
 *
 * @example
 * ```jsx
 * <Accordion>
 *   <Accordion.Item>
 *     <Accordion.Header>Section 1</Accordion.Header>
 *     <Accordion.Content>Content 1</Accordion.Content>
 *   </Accordion.Item>
 *   <Accordion.Item>
 *     <Accordion.Header>Section 2</Accordion.Header>
 *     <Accordion.Content>Content 2</Accordion.Content>
 *   </Accordion.Item>
 * </Accordion>
 * ```
 */
export const Accordion = forwardRef((_a, ref) => {
    var { className, variant = "default", size = "medium", indent = true, as: Component = "div" } = _a, rest = __rest(_a, ["className", "variant", "size", "indent", "as"]);
    const localRef = useRef(null);
    const mergedRef = useMergeRefs(localRef, ref);
    useEffect(() => {
        var _a;
        if (process.env.NODE_ENV === "production" || !localRef.current) {
            return;
        }
        if ((_a = localRef.current.nextElementSibling) === null || _a === void 0 ? void 0 : _a.classList.contains("aksel-accordion")) {
            consoleWarning("Do not put multiple accordions directly after each other. Use one <Accordion> with multiple <Accordion.Item> instead.", localRef.current);
        }
        if (localRef.current.children.length === 1) {
            consoleWarning("Accordions should have more than one item. Consider using ExpansionPanel instead.", localRef.current);
        }
    }, []);
    return (React.createElement(AccordionContext.Provider, { value: {
            size,
            mounted: true,
            variant,
        } },
        React.createElement(Component, Object.assign({}, omit(rest, ["headingSize"]), { className: cl("aksel-accordion", className, `aksel-accordion--${size}`, { "aksel-accordion--indent": indent }), ref: mergedRef }))));
});
Accordion.Header = AccordionHeader;
Accordion.Content = AccordionContent;
Accordion.Item = AccordionItem;
export default Accordion;
export { AccordionItem, AccordionHeader, AccordionContent };
//# sourceMappingURL=Accordion.js.map