import { useState, useEffect } from 'react';
import { useSafePromise } from '../hooks/useSafePromise';
export var useDefaultOptions = function (loadOptions) {
    var _a = useState([]), defaultOptions = _a[0], setDefaultOptions = _a[1];
    var _b = useState(null), initialDefaultOptions = _b[0], setInitialDefaultOptions = _b[1];
    var _c = useState(false), isLoading = _c[0], setIsLoading = _c[1];
    var safePromise = useSafePromise();
    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 };
};
