"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const react_1 = tslib_1.__importDefault(require("react"));
const reducers_1 = require("../../common/reducers");
const apis_1 = require("../services/apis");
const api_1 = require("../../common/api");
const utils_1 = require("../../common/utils");
const { addAlert } = reducers_1.alertsSlice.actions;
const useClusterPreflightRequirements = (clusterId) => {
    const [preflightRequirements, setPreflightRequirements] = react_1.default.useState();
    const [error, setError] = react_1.default.useState('');
    react_1.default.useEffect(() => {
        const fetchFunc = () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
            try {
                const { data } = yield apis_1.ClustersAPI.getPreflightRequirements(clusterId);
                setPreflightRequirements(data);
            }
            catch (e) {
                setError((0, utils_1.getErrorMessage)(e));
                // report error systematically at one place show defaults instead
                (0, api_1.handleApiError)(e, () => addAlert({
                    title: 'Failed to retrieve preflight cluster requirements',
                    message: (0, api_1.getApiErrorMessage)(e),
                }));
            }
        });
        void fetchFunc();
    }, [setPreflightRequirements, setError, clusterId]);
    return {
        preflightRequirements,
        error,
        isLoading: !error && !preflightRequirements,
    };
};
exports.default = useClusterPreflightRequirements;
//# sourceMappingURL=useClusterPreflightRequirements.js.map