"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = useUsedClusterNames;
const tslib_1 = require("tslib");
const react_1 = tslib_1.__importDefault(require("react"));
const api_1 = require("../../common/api");
const apis_1 = require("../services/apis");
const common_1 = require("../../common");
function useUsedClusterNames(clusterId) {
    const [usedClusterNames, setUsedClusterNames] = react_1.default.useState();
    const { addAlert } = (0, common_1.useAlerts)();
    const fetcher = react_1.default.useCallback(() => tslib_1.__awaiter(this, void 0, void 0, function* () {
        try {
            const { data: clusters } = yield apis_1.ClustersAPI.list();
            const names = clusters
                .filter((c) => c.id !== clusterId)
                .map((c) => `${c.name || ''}.${c.baseDnsDomain || ''}`);
            setUsedClusterNames(names);
        }
        catch (e) {
            setUsedClusterNames([]);
            (0, api_1.handleApiError)(e, () => addAlert({
                title: 'Failed to retrieve names of existing clusters.',
                message: (0, api_1.getApiErrorMessage)(e),
            }));
        }
    }), [addAlert, clusterId]);
    react_1.default.useEffect(() => {
        void fetcher();
        // eslint-disable-next-line react-hooks/exhaustive-deps
    }, []);
    return { usedClusterNames };
}
//# sourceMappingURL=useUsedClusterNames.js.map