"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 });
const react_1 = __importStar(require("react"));
const Combobox_1 = __importDefault(require("./Combobox"));
const filteredOptionsContext_1 = require("./FilteredOptions/filteredOptionsContext");
const Input_context_1 = require("./Input/Input.context");
const selectedOptionsContext_1 = require("./SelectedOptions/selectedOptionsContext");
const combobox_utils_1 = require("./combobox-utils");
const customOptionsContext_1 = require("./customOptionsContext");
/**
 * A component that allows the user to search in a list of options
 *
 * Has options for allowing only one or multiple options to be selected,
 * or adding new, user-submitted values.
 *
 * @see [📝 Documentation](https://aksel.nav.no/komponenter/core/combobox)
 *
 * @example
 * ```jsx
 * const options = ["apple", "banana", "orange"];
 *
 * return (
 *    <Combobox
 *      label="Velg en verdi"
 *      options={options}
 *      id="my-combobox"
 *      shouldAutoComplete
 *    />
 * )
 * ```
 */
const ComboboxProvider = (0, react_1.forwardRef)((props, ref) => {
    const { allowNewValues = false, children, defaultValue, disabled, readOnly, error, errorId, filteredOptions: externalFilteredOptions, id, isListOpen, isLoading = false, isMultiSelect, onToggleSelected, selectedOptions: externalSelectedOptions, maxSelected, options: externalOptions, value, onChange, onClear, shouldAutocomplete: externalShouldAutocomplete, size } = props, rest = __rest(props, ["allowNewValues", "children", "defaultValue", "disabled", "readOnly", "error", "errorId", "filteredOptions", "id", "isListOpen", "isLoading", "isMultiSelect", "onToggleSelected", "selectedOptions", "maxSelected", "options", "value", "onChange", "onClear", "shouldAutocomplete", "size"]);
    const options = (0, combobox_utils_1.mapToComboboxOptionArray)(externalOptions) || [];
    const filteredOptions = (0, combobox_utils_1.mapToComboboxOptionArray)(externalFilteredOptions);
    const selectedOptions = (0, combobox_utils_1.mapToComboboxOptionArray)(externalSelectedOptions);
    const userAgent = typeof navigator === "undefined" ? "" : navigator.userAgent;
    const isFirefoxOnAndroid = userAgent.includes("Android") && userAgent.includes("Firefox/");
    const shouldAutocomplete = !isFirefoxOnAndroid && externalShouldAutocomplete;
    return (react_1.default.createElement(Input_context_1.InputContextProvider, { value: {
            defaultValue,
            description: rest.description,
            disabled,
            readOnly,
            error,
            errorId,
            id,
            value,
            onChange,
            onClear,
            shouldAutocomplete,
            size,
        } },
        react_1.default.createElement(customOptionsContext_1.CustomOptionsProvider, { value: { isMultiSelect } },
            react_1.default.createElement(selectedOptionsContext_1.SelectedOptionsProvider, { value: {
                    allowNewValues,
                    isMultiSelect,
                    selectedOptions,
                    maxSelected,
                    onToggleSelected,
                    options,
                } },
                react_1.default.createElement(filteredOptionsContext_1.FilteredOptionsProvider, { value: {
                        allowNewValues,
                        filteredOptions,
                        isListOpen,
                        isLoading,
                        options,
                    } },
                    react_1.default.createElement(Combobox_1.default, Object.assign({ ref: ref }, rest), children))))));
});
exports.default = ComboboxProvider;
//# sourceMappingURL=ComboboxProvider.js.map