"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = useManagedDomains;
const tslib_1 = require("tslib");
const react_1 = tslib_1.__importDefault(require("react"));
const common_1 = require("../../common");
const api_1 = require("../../common/api");
const apis_1 = require("../services/apis");
function useManagedDomains() {
    const [managedDomains, setManagedDomains] = react_1.default.useState();
    const { addAlert } = (0, common_1.useAlerts)();
    const fetchManagedDomains = react_1.default.useCallback(() => tslib_1.__awaiter(this, void 0, void 0, function* () {
        try {
            const { data: domains } = yield apis_1.ManagedDomainsAPI.list();
            setManagedDomains(domains);
        }
        catch (e) {
            setManagedDomains([]);
            (0, api_1.handleApiError)(e, () => addAlert({ title: 'Failed to retrieve managed domains', message: (0, api_1.getApiErrorMessage)(e) }));
        }
    }), [addAlert]);
    react_1.default.useEffect(() => {
        if (!managedDomains) {
            void fetchManagedDomains();
        }
    }, []); // eslint-disable-line react-hooks/exhaustive-deps
    return managedDomains;
}
//# sourceMappingURL=useManagedDomains.js.map