"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
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;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.AccordionContent = exports.AccordionHeader = exports.AccordionItem = exports.Accordion = void 0;
const react_1 = __importStar(require("react"));
const utils_external_1 = require("../utils-external");
const helpers_1 = require("../utils/helpers");
const consoleWarning_1 = require("../utils/helpers/consoleWarning");
const hooks_1 = require("../utils/hooks");
const AccordionContent_1 = __importDefault(require("./AccordionContent"));
exports.AccordionContent = AccordionContent_1.default;
const AccordionContext_1 = require("./AccordionContext");
const AccordionHeader_1 = __importDefault(require("./AccordionHeader"));
exports.AccordionHeader = AccordionHeader_1.default;
const AccordionItem_1 = __importDefault(require("./AccordionItem"));
exports.AccordionItem = AccordionItem_1.default;
/**
 * 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>
 * ```
 */
exports.Accordion = (0, react_1.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 = (0, react_1.useRef)(null);
    const mergedRef = (0, hooks_1.useMergeRefs)(localRef, ref);
    (0, react_1.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")) {
            (0, consoleWarning_1.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) {
            (0, consoleWarning_1.consoleWarning)("Accordions should have more than one item. Consider using ExpansionPanel instead.", localRef.current);
        }
    }, []);
    return (react_1.default.createElement(AccordionContext_1.AccordionContext.Provider, { value: {
            size,
            mounted: true,
            variant,
        } },
        react_1.default.createElement(Component, Object.assign({}, (0, utils_external_1.omit)(rest, ["headingSize"]), { className: (0, helpers_1.cl)("aksel-accordion", className, `aksel-accordion--${size}`, { "aksel-accordion--indent": indent }), ref: mergedRef }))));
});
exports.Accordion.Header = AccordionHeader_1.default;
exports.Accordion.Content = AccordionContent_1.default;
exports.Accordion.Item = AccordionItem_1.default;
exports.default = exports.Accordion;
//# sourceMappingURL=Accordion.js.map