"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useDefaultOptions = void 0;
var react_1 = require("react");
var useSafePromise_1 = require("../hooks/useSafePromise");
var useDefaultOptions = function (loadOptions) {
    var _a = (0, react_1.useState)([]), defaultOptions = _a[0], setDefaultOptions = _a[1];
    var _b = (0, react_1.useState)(null), initialDefaultOptions = _b[0], setInitialDefaultOptions = _b[1];
    var _c = (0, react_1.useState)(false), isLoading = _c[0], setIsLoading = _c[1];
    var safePromise = (0, useSafePromise_1.useSafePromise)();
    (0, react_1.useEffect)(function () {
        setDefaultOptions([]);
        setIsLoading(true);
        safePromise(loadOptions(''))
            .then(function (options) {
            setDefaultOptions(options);
            setInitialDefaultOptions(function (prevValue) { return prevValue || options; });
            setIsLoading(false);
        })
            .catch(function () {
            setIsLoading(false);
        });
    }, [loadOptions]); // eslint-disable-line
    return { defaultOptions: defaultOptions, initialDefaultOptions: initialDefaultOptions, isLoading: isLoading };
};
exports.useDefaultOptions = useDefaultOptions;
