"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ClusterDeploymentWizard = void 0;
const tslib_1 = require("tslib");
const React = tslib_1.__importStar(require("react"));
const use_translation_wrapper_1 = require("../../../common/hooks/use-translation-wrapper");
const react_core_1 = require("@patternfly/react-core");
const common_1 = require("../../../common");
const featureSupportLevels_1 = require("../featureSupportLevels");
const YamlPreview_1 = require("../YamlPreview");
const constants_1 = require("./constants");
const ClusterDeploymentWizardContext_1 = require("./ClusterDeploymentWizardContext");
const helpers_1 = require("./helpers");
const clusterDetails_1 = require("./clusterDetails");
const hostSelection_1 = require("./hostSelection");
const hostDiscovery_1 = require("./hostDiscovery");
const networking_1 = require("./networking");
const review_1 = require("./review");
const customManifests_1 = require("./customManifests");
const hooks_1 = require("../../hooks");
const ClusterDeploymentWizard = (_a) => {
    var _b, _c;
    var { className, onSaveDetails, onSaveNetworking, onSaveHostsSelection, onClose, onFinish, hostActions, usedClusterNames, fetchSecret, clusterDeployment, agentClusterInstall, bareMetalHosts, clusterImages, aiConfigMap, infraEnv, fetchInfraEnv, initialStep, isPreviewOpen, setPreviewOpen, fetchManagedClusters, fetchKlusterletAddonConfig, onSaveISOParams, onCreateBMH, isNutanix, onChangeBMHHostname } = _a, rest = tslib_1.__rest(_a, ["className", "onSaveDetails", "onSaveNetworking", "onSaveHostsSelection", "onClose", "onFinish", "hostActions", "usedClusterNames", "fetchSecret", "clusterDeployment", "agentClusterInstall", "bareMetalHosts", "clusterImages", "aiConfigMap", "infraEnv", "fetchInfraEnv", "initialStep", "isPreviewOpen", "setPreviewOpen", "fetchManagedClusters", "fetchKlusterletAddonConfig", "onSaveISOParams", "onCreateBMH", "isNutanix", "onChangeBMHHostname"]);
    const { t } = (0, use_translation_wrapper_1.useTranslation)();
    const { code, loadingResources } = (0, YamlPreview_1.useYamlPreview)({
        agentClusterInstall,
        clusterDeployment,
        fetchSecret,
        fetchManagedClusters,
        fetchKlusterletAddonConfig,
    });
    const [agents, loaded, error] = (0, hooks_1.useAgents)({ isList: true });
    // if initialStep is set, it is either 'host-selection' or 'host-discovery', both at index 4
    // if initialStep is not set, start at 'cluster-details' which is at index 2
    const startIndex = initialStep ? 4 : 2;
    const stepNames = (0, constants_1.wizardStepNames)(t);
    const isAIFlow = !!infraEnv;
    if (!loaded) {
        return React.createElement(common_1.LoadingState, null);
    }
    else if (error) {
        return React.createElement(common_1.ErrorState, null);
    }
    return (React.createElement(react_core_1.Grid, { style: { height: '100%' } },
        React.createElement(react_core_1.GridItem, { span: isPreviewOpen ? 7 : 12 },
            React.createElement(common_1.AlertsContextProvider, null,
                React.createElement(featureSupportLevels_1.ACMFeatureSupportLevelProvider, { clusterImages: clusterImages, isEditClusterFlow: true },
                    React.createElement(ClusterDeploymentWizardContext_1.ClusterDeploymentWizardContextProvider, { agentClusterInstall: agentClusterInstall },
                        React.createElement(react_core_1.Wizard, { isVisitRequired: true, startIndex: startIndex, className: className, onClose: onClose },
                            React.createElement(react_core_1.WizardStep, { name: stepNames['installation-type'], id: 'installation-type', isDisabled: true }),
                            React.createElement(react_core_1.WizardStep, { name: stepNames['cluster-details'], id: 'cluster-details' },
                                React.createElement(clusterDetails_1.ClusterDeploymentDetailsStep, { clusterImages: clusterImages, usedClusterNames: usedClusterNames, clusterDeployment: clusterDeployment, agentClusterInstall: agentClusterInstall, agents: agents, onSaveDetails: onSaveDetails, isPreviewOpen: isPreviewOpen, infraEnv: infraEnv, isNutanix: isNutanix })),
                            React.createElement(react_core_1.WizardStep, { name: stepNames['automation'], id: 'automation', isDisabled: true }),
                            (0, helpers_1.isCIMFlow)(clusterDeployment) ? (React.createElement(react_core_1.WizardStep, { name: stepNames['hosts-selection'], id: 'host-selection' }, ((_b = agentClusterInstall === null || agentClusterInstall === void 0 ? void 0 : agentClusterInstall.metadata) === null || _b === void 0 ? void 0 : _b.name) ? (React.createElement(hostSelection_1.ClusterDeploymentHostSelectionStep, { clusterDeployment: clusterDeployment, agentClusterInstall: agentClusterInstall, onSaveHostsSelection: onSaveHostsSelection, agents: agents, aiConfigMap: aiConfigMap, onEditRole: hostActions.onEditRole, onSetInstallationDiskId: hostActions.onSetInstallationDiskId, isNutanix: isNutanix })) : (React.createElement(common_1.LoadingState, null)))) : (React.createElement(react_core_1.WizardStep, { name: stepNames['hosts-discovery'], id: 'host-discovery' }, isAIFlow && onSaveISOParams && onCreateBMH ? (React.createElement(hostDiscovery_1.ClusterDeploymentHostsDiscoveryStep, Object.assign({ clusterDeployment: clusterDeployment, agentClusterInstall: agentClusterInstall, agents: agents, bareMetalHosts: bareMetalHosts, aiConfigMap: aiConfigMap, infraEnv: infraEnv, fetchSecret: fetchSecret, onChangeBMHHostname: onChangeBMHHostname, onEditRole: hostActions.onEditRole, onSetInstallationDiskId: hostActions.onSetInstallationDiskId, onDeleteHost: hostActions.onDeleteHost, onSaveISOParams: onSaveISOParams, onCreateBMH: onCreateBMH }, rest))) : (React.createElement(common_1.LoadingState, null)))),
                            React.createElement(react_core_1.WizardStep, { name: stepNames['networking'], id: 'networking' },
                                React.createElement(networking_1.ClusterDeploymentNetworkingStep, { clusterDeployment: clusterDeployment, agentClusterInstall: agentClusterInstall, agents: agents, onSaveNetworking: onSaveNetworking, onEditHost: hostActions.onEditHost, onEditRole: hostActions.onEditRole, fetchInfraEnv: fetchInfraEnv, isPreviewOpen: isPreviewOpen, onSetInstallationDiskId: hostActions.onSetInstallationDiskId, isNutanix: isNutanix })),
                            React.createElement(react_core_1.WizardStep, { name: stepNames['custom-manifests'], id: 'custom-manifests' },
                                React.createElement(customManifests_1.ClusterDeploymentCustomManifestsStep, { agentClusterInstall: agentClusterInstall })),
                            React.createElement(react_core_1.WizardStep, { name: stepNames['review'], id: 'review' },
                                React.createElement(review_1.ClusterDeploymentReviewStep, { onFinish: onFinish, clusterDeployment: clusterDeployment, agentClusterInstall: agentClusterInstall, agents: agents, clusterImages: clusterImages, infraEnv: infraEnv }))))))),
        isPreviewOpen && (React.createElement(react_core_1.GridItem, { span: 5 },
            React.createElement(YamlPreview_1.YamlPreview, { code: code, setPreviewOpen: setPreviewOpen, loading: loadingResources }, `${((_c = clusterDeployment.metadata) === null || _c === void 0 ? void 0 : _c.name) || ''} cluster`)))));
};
exports.ClusterDeploymentWizard = ClusterDeploymentWizard;
//# sourceMappingURL=ClusterDeploymentWizard.js.map