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, useContext } from "react";
import { ChevronDownIcon } from "@navikt/aksel-icons";
import { Heading } from "../typography/index.js";
import { cl, composeEventHandlers } from "../utils/helpers/index.js";
import { AccordionContext } from "./AccordionContext.js";
import { AccordionItemContext } from "./AccordionItem.js";
const AccordionHeader = forwardRef((_a, ref) => {
    var { children, className, onClick } = _a, rest = __rest(_a, ["children", "className", "onClick"]);
    const itemContext = useContext(AccordionItemContext);
    const accordionContext = useContext(AccordionContext);
    if (itemContext === null) {
        console.error("<Accordion.Header> has to be used within an <Accordion.Item>, which in turn must be within an <Accordion>");
        return null;
    }
    return (React.createElement("button", Object.assign({ ref: ref, "data-color": (accordionContext === null || accordionContext === void 0 ? void 0 : accordionContext.variant) === "neutral" ? "neutral" : undefined }, rest, { className: cl("aksel-accordion__header", className), onClick: composeEventHandlers(onClick, itemContext.toggleOpen), "aria-expanded": itemContext.open, type: "button" }),
        React.createElement("span", { className: "aksel-accordion__icon-wrapper" },
            React.createElement(ChevronDownIcon, { className: "aksel-accordion__header-chevron", "aria-hidden": true })),
        React.createElement(Heading, { size: (accordionContext === null || accordionContext === void 0 ? void 0 : accordionContext.size) === "large" ? "small" : "xsmall", as: "span" }, children)));
});
export default AccordionHeader;
//# sourceMappingURL=AccordionHeader.js.map