"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getAddHostsTabState = void 0;
const FeatureSupportLevelProvider_1 = require("../featureSupportLevels/FeatureSupportLevelProvider");
const isSNOExpansionAllowed = (cluster) => {
    if (cluster.aiSupportLevels) {
        return (0, FeatureSupportLevelProvider_1.getFeatureSupported)(cluster.aiSupportLevels.features || [], 'SINGLE_NODE_EXPANSION');
    }
    else {
        return false;
    }
};
const makeState = (state, tooltipMessage = '') => {
    switch (state) {
        case 'hidden':
            return {
                showTab: false,
                isDisabled: false,
                tabTooltip: '',
            };
        case 'visible':
            return {
                showTab: true,
                isDisabled: false,
                tabTooltip: tooltipMessage,
            };
        case 'disabled':
            return {
                showTab: true,
                isDisabled: true,
                tabTooltip: tooltipMessage,
            };
    }
};
const getAddHostsTabState = (cluster) => {
    var _a, _b, _c, _d;
    // Prioritize aiCluster.status over cluster.state to prevent inconsistencies
    // where metrics might show the cluster as ready while installation is still in progress
    const isClusterStateReady = ((_a = cluster.aiCluster) === null || _a === void 0 ? void 0 : _a.status)
        ? /ready|installed/.test(cluster.aiCluster.status)
        : /ready|installed/.test(cluster.state);
    const wasInstalledUsingAssistedInstaller = ((_b = cluster.product) === null || _b === void 0 ? void 0 : _b.id) === 'OCP-AssistedInstall';
    // Checking if the Day1 cluster has reported metrics, so it can be determined if it's an SNO / multi node and has required information
    const day1ClusterHostCount = ((_d = (_c = cluster.metrics) === null || _c === void 0 ? void 0 : _c.nodes) === null || _d === void 0 ? void 0 : _d.total) || 0;
    // Disable Add Hosts with the following priority:
    // 1) Cluster is not ready
    // 2) Cluster was not installed using Assisted Installer
    // 3) Cluster has no metrics
    if (!isClusterStateReady) {
        return makeState('disabled', 'Cluster is not ready. Please wait for the cluster to be ready and try again.');
    }
    else if (!wasInstalledUsingAssistedInstaller) {
        return makeState('disabled', 'Hosts cannot be added to an existing cluster that was not installed using Assisted Installer. Install a new cluster and try again.');
    }
    else if (!cluster.metrics) {
        return makeState('disabled', 'Cluster has no metrics. Please wait for the cluster to have metrics and try again.');
    }
    // At this point the cluster is ready, installed using Assisted Installer, and has metrics
    let tabState = makeState('visible');
    if (day1ClusterHostCount === 1 && !isSNOExpansionAllowed(cluster)) {
        // The cluster has metrics etc., but it's an SNO with an OpenshiftVersion that doesn't support Day2 flow
        tabState = makeState('disabled', 'OpenShift version not supported for SNO expansion. Hosts cannot be added to an existing SNO cluster that was installed with any OpenShift version older than 4.11. Upgrade to a newer OpenShift version and try again.');
    }
    return tabState;
};
exports.getAddHostsTabState = getAddHostsTabState;
//# sourceMappingURL=utils.js.map