"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const react_1 = tslib_1.__importDefault(require("react"));
const react_core_1 = require("@patternfly/react-core");
const wizardTransition_1 = require("./wizardTransition");
const ClusterWizardContext_1 = require("./ClusterWizardContext");
const constants_1 = require("./constants");
const WizardNavItem_1 = tslib_1.__importDefault(require("../../../common/components/ui/WizardNavItem"));
const isStepValid = (stepId, cluster) => {
    if (!cluster) {
        return true;
    }
    switch (stepId) {
        case 'cluster-details':
            return !cluster.validationsInfo || (0, wizardTransition_1.canNextClusterDetails)({ cluster });
        case 'static-ip-yaml-view':
        case 'static-ip-host-configurations':
        case 'static-ip-network-wide-configurations':
            return (0, wizardTransition_1.canNextClusterDetails)({ cluster });
        case 'host-discovery':
            return (0, wizardTransition_1.canNextHostDiscovery)({ cluster });
        case 'storage':
            return (0, wizardTransition_1.canNextStorage)({ cluster });
        case 'networking':
            return (0, wizardTransition_1.canNextNetwork)({ cluster });
        default:
            return true;
    }
};
const ClusterWizardNavigation = ({ cluster }) => {
    const clusterWizardContext = (0, ClusterWizardContext_1.useClusterWizardContext)();
    const isStepIdxAfterCurrent = (idx) => {
        return !clusterWizardContext.wizardStepIds
            .slice(idx)
            .includes(clusterWizardContext.currentStepId);
    };
    const isStepDisabled = (idx, stepId) => {
        return stepId === 'cluster-details' ? false : isStepIdxAfterCurrent(idx);
    };
    const getNavItem = (idx, stepId) => {
        return (react_1.default.createElement(WizardNavItem_1.default, { stepIndex: idx, key: stepId, id: `wizard-nv-${stepId}`, content: constants_1.wizardStepNames[stepId], onClick: () => clusterWizardContext.setCurrentStepId(stepId), isCurrent: clusterWizardContext.currentStepId === stepId, isDisabled: isStepDisabled(idx, stepId), isValid: () => isStepValid(stepId, cluster), "data-testid": `cluster-wizard-nav-item-${stepId}` }));
    };
    const getStaticIpFormViewNavItem = (idx) => {
        return (react_1.default.createElement(WizardNavItem_1.default, { stepIndex: idx, isExpandable: true, content: "Static network configurations", key: "static-network-configuration-form-view", isCurrent: (0, wizardTransition_1.isStaticIpStep)(clusterWizardContext.currentStepId), isDisabled: isStepIdxAfterCurrent(idx), "data-testid": `cluster-wizard-nav-item-static-network-configuration-form-view` },
            react_1.default.createElement(react_core_1.WizardNav, { isInnerList: true, "data-testid": "cluster-wizard-nav-item-static-network-configuration-form-view-inner-list" }, constants_1.staticIpFormViewSubSteps.map((stepId, subIdx) => {
                return getNavItem(idx + subIdx, stepId);
            }))));
    };
    const getWizardNavItems = () => {
        const navItems = [];
        let i = 0;
        while (i < clusterWizardContext.wizardStepIds.length) {
            const stepId = clusterWizardContext.wizardStepIds[i];
            if (stepId !== 'static-ip-network-wide-configurations') {
                navItems.push(getNavItem(i, stepId));
                i += 1;
            }
            else {
                navItems.push(getStaticIpFormViewNavItem(i));
                //skip iteration on form view sub steps
                i += 2;
            }
        }
        return navItems;
    };
    return react_1.default.createElement(react_core_1.WizardNav, { "data-testid": "cluster-wizard-nav" }, getWizardNavItems());
};
exports.default = ClusterWizardNavigation;
//# sourceMappingURL=ClusterWizardNavigation.js.map