"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const react_1 = tslib_1.__importDefault(require("react"));
const react_router_dom_v5_compat_1 = require("react-router-dom-v5-compat");
const react_core_1 = require("@patternfly/react-core");
const common_1 = require("../../../common");
const wizardTransition_1 = require("./wizardTransition");
const ClusterWizardContext_1 = require("./ClusterWizardContext");
const ClusterWizardStepValidationsAlert_1 = tslib_1.__importDefault(require("../../../common/components/clusterWizard/ClusterWizardStepValidationsAlert"));
const use_translation_wrapper_1 = require("../../../common/hooks/use-translation-wrapper");
const fetchEvents_1 = require("../fetching/fetchEvents");
const use_feature_1 = require("../../hooks/use-feature");
const ModalDialogsContext_1 = require("../hosts/ModalDialogsContext");
const defaultAlertTitle = 'Provided cluster configuration is not valid';
const ValidationSection = ({ cluster, errorFields = [], alertTitle, alertContent, }) => {
    const { currentStepId } = (0, ClusterWizardContext_1.useClusterWizardContext)();
    const validationsInfo = cluster && (0, common_1.selectClusterValidationsInfo)(cluster);
    const { uiSettings } = (0, ClusterWizardContext_1.useClusterWizardContext)();
    const { t } = (0, use_translation_wrapper_1.useTranslation)();
    let _alertContent = alertContent;
    if (_alertContent === undefined) {
        _alertContent = `The following fields are invalid or missing: 
    ${errorFields.map((field) => (0, common_1.clusterFieldLabels)(t)[field] || field).join(', ')}.`;
    }
    return (react_1.default.createElement(react_core_1.AlertGroup, null,
        !!errorFields.length && (react_1.default.createElement(react_core_1.Alert, { variant: react_core_1.AlertVariant.danger, title: alertTitle || defaultAlertTitle, isInline: true }, _alertContent)),
        cluster && (react_1.default.createElement(ClusterWizardStepValidationsAlert_1.default, { currentStepId: currentStepId, clusterStatus: cluster.status, hosts: (cluster === null || cluster === void 0 ? void 0 : cluster.hosts) || [], validationsInfo: validationsInfo, wizardStepsValidationsMap: wizardTransition_1.wizardStepsValidationsMap, lastInstallationPreparation: cluster['last-installation-preparation'], uiSettings: uiSettings }))));
};
const ClusterWizardFooter = (_a) => {
    var { cluster, additionalActions, errorFields, alertTitle, alertContent, onCancel } = _a, rest = tslib_1.__rest(_a, ["cluster", "additionalActions", "errorFields", "alertTitle", "alertContent", "onCancel"]);
    const { alerts } = (0, common_1.useAlerts)();
    const navigate = (0, react_router_dom_v5_compat_1.useNavigate)();
    const isSingleClusterFeatureEnabled = (0, use_feature_1.useFeature)('ASSISTED_INSTALLER_SINGLE_CLUSTER_FEATURE');
    const { currentStepId } = (0, ClusterWizardContext_1.useClusterWizardContext)();
    const { resetSingleClusterDialog } = (0, ModalDialogsContext_1.useModalDialogsContext)();
    const handleCancel = react_1.default.useCallback(() => navigate('/cluster-list'), [navigate]);
    const handleReset = react_1.default.useCallback(() => {
        resetSingleClusterDialog.open({ cluster });
    }, [resetSingleClusterDialog, cluster]);
    const alertsSection = alerts.length ? react_1.default.createElement(common_1.Alerts, null) : undefined;
    const errorsSection = (react_1.default.createElement(ValidationSection, { cluster: cluster, errorFields: errorFields, alertTitle: alertTitle, alertContent: alertContent }));
    return (react_1.default.createElement(common_1.WizardFooter, Object.assign({ alerts: alertsSection, errors: errorsSection, onCancel: isSingleClusterFeatureEnabled ? undefined : onCancel || handleCancel, onReset: isSingleClusterFeatureEnabled && currentStepId !== 'cluster-details'
            ? handleReset
            : undefined, leftExtraActions: additionalActions, cluster: cluster, onFetchEvents: fetchEvents_1.onFetchEvents }, rest, { "data-testid": "cluster-wizard-footer" })));
};
exports.default = ClusterWizardFooter;
//# sourceMappingURL=ClusterWizardFooter.js.map