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 { cl, composeEventHandlers } from "../utils/helpers/index.js";
import { consoleWarning } from "../utils/helpers/consoleWarning.js";
import { useMergeRefs } from "../utils/hooks/index.js";
import { DropdownContext } from "./context.js";
export const DropdownToggle = forwardRef((_a, ref) => {
    var { className, onClick } = _a, rest = __rest(_a, ["className", "onClick"]);
    const context = useContext(DropdownContext);
    const mergedRef = useMergeRefs(context === null || context === void 0 ? void 0 : context.setAnchorEl, ref);
    if (!context) {
        consoleWarning("<Dropdown.Toggle /> has to be wrapped inside <Dropdown />");
        return null;
    }
    const { handleToggle, isOpen } = context;
    const handleClick = () => {
        handleToggle(!isOpen);
    };
    return (React.createElement("button", Object.assign({}, rest, { ref: mergedRef, onClick: composeEventHandlers(onClick, handleClick), "aria-expanded": isOpen, className: cl("aksel-dropdown__toggle", className) })));
});
export default DropdownToggle;
//# sourceMappingURL=Toggle.js.map