"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const react_1 = __importDefault(require("react"));
const aksel_icons_1 = require("@navikt/aksel-icons");
const typography_1 = require("../../../typography");
const helpers_1 = require("../../../utils/helpers");
const i18n_hooks_1 = require("../../../utils/i18n/i18n.hooks");
const Input_context_1 = require("../Input/Input.context");
const selectedOptionsContext_1 = require("../SelectedOptions/selectedOptionsContext");
const combobox_utils_1 = require("../combobox-utils");
const filtered_options_util_1 = __importDefault(require("./filtered-options-util"));
const filteredOptionsContext_1 = require("./filteredOptionsContext");
const AddNewOption = () => {
    const { inputProps: { id }, size, searchTerm, } = (0, Input_context_1.useInputContext)();
    const { setIsMouseLastUsedInputDevice, toggleIsListOpen, activeDescendantId, virtualFocus, } = (0, filteredOptionsContext_1.useFilteredOptionsContext)();
    const { isMultiSelect, selectedOptions, toggleOption } = (0, selectedOptionsContext_1.useSelectedOptionsContext)();
    const translate = (0, i18n_hooks_1.useI18n)("Combobox");
    return (react_1.default.createElement("li", { tabIndex: -1, onMouseMove: () => {
            if (activeDescendantId !== filtered_options_util_1.default.getAddNewOptionId(id)) {
                virtualFocus.moveFocusToElement(filtered_options_util_1.default.getAddNewOptionId(id));
                setIsMouseLastUsedInputDevice(true);
            }
        }, onPointerUp: (event) => {
            toggleOption((0, combobox_utils_1.toComboboxOption)(searchTerm), event);
            if (!isMultiSelect && !(0, combobox_utils_1.isInList)(searchTerm, selectedOptions))
                toggleIsListOpen(false);
        }, id: filtered_options_util_1.default.getAddNewOptionId(id), className: (0, helpers_1.cl)("aksel-combobox__list-item aksel-combobox__list-item--new-option", {
            "aksel-combobox__list-item--new-option--focus": activeDescendantId === filtered_options_util_1.default.getAddNewOptionId(id),
        }), role: "option", "aria-selected": false },
        react_1.default.createElement(aksel_icons_1.PlusIcon, { "aria-hidden": true }),
        react_1.default.createElement(typography_1.BodyShort, { size: size },
            translate("addOption"),
            " ",
            react_1.default.createElement(typography_1.Label, { as: "span", size: size },
                "\u201C",
                searchTerm,
                "\u201D"))));
};
exports.default = AddNewOption;
//# sourceMappingURL=AddNewOption.js.map