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 { MagnifyingGlassIcon } from "@navikt/aksel-icons";
import { Button } from "../../button/index.js";
import { cl, composeEventHandlers } from "../../utils/helpers/index.js";
import { consoleWarning } from "../../utils/helpers/consoleWarning.js";
import { useI18n } from "../../utils/i18n/i18n.hooks.js";
import { SearchContext } from "./context.js";
const SearchButton = forwardRef((_a, ref) => {
    var _b;
    var { className, children, disabled, onClick } = _a, rest = __rest(_a, ["className", "children", "disabled", "onClick"]);
    const translate = useI18n("Search");
    const context = useContext(SearchContext);
    if (context === null) {
        consoleWarning("<Search.Button> has to be wrapped inside <Search />");
        return null;
    }
    const { size, variant, handleClick } = context;
    return (React.createElement(Button, Object.assign({ type: "submit" }, rest, { ref: ref, size: size, variant: variant === "secondary" ? "secondary" : "primary", className: cl("aksel-search__button-search", className), disabled: (_b = context === null || context === void 0 ? void 0 : context.disabled) !== null && _b !== void 0 ? _b : disabled, onClick: composeEventHandlers(onClick, handleClick), icon: React.createElement(MagnifyingGlassIcon, Object.assign({}, (children
            ? { "aria-hidden": true }
            : { title: translate("search") }))) }), children));
});
export default SearchButton;
//# sourceMappingURL=SearchButton.js.map