import React, { useCallback, useState } from "react";
import { createStrictContext } from "../../utils/helpers/index.js";
import { useInputContext } from "./Input/Input.context.js";
const { Provider: ComboboxCustomOptionsProvider, useContext: useComboboxCustomOptions, } = createStrictContext({
    name: "ComboboxCustomOptions",
    errorMessage: "useComboboxCustomOptions must be used within a ComboboxCustomOptionsProvider",
});
const CustomOptionsProvider = ({ children, value, }) => {
    const [customOptions, setCustomOptions] = useState([]);
    const { focusInput } = useInputContext();
    const { isMultiSelect } = value;
    const removeCustomOption = useCallback((option) => {
        setCustomOptions((prevCustomOptions) => prevCustomOptions.filter((o) => o.label !== option.label));
        focusInput();
    }, [focusInput]);
    const addCustomOption = useCallback((option) => {
        if (isMultiSelect) {
            setCustomOptions((prevOptions) => [...prevOptions, option]);
        }
        else {
            setCustomOptions([option]);
        }
        focusInput();
    }, [focusInput, isMultiSelect]);
    const customOptionsState = {
        customOptions,
        removeCustomOption,
        addCustomOption,
        setCustomOptions,
    };
    return (React.createElement(ComboboxCustomOptionsProvider, Object.assign({}, customOptionsState), children));
};
export { CustomOptionsProvider, useComboboxCustomOptions };
//# sourceMappingURL=customOptionsContext.js.map