"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const react_1 = tslib_1.__importDefault(require("react"));
const common_1 = require("../../../common");
const ClusterWizardContext_1 = require("./ClusterWizardContext");
const ClusterWizardFooter_1 = tslib_1.__importDefault(require("./ClusterWizardFooter"));
const ClusterWizardNavigation_1 = tslib_1.__importDefault(require("./ClusterWizardNavigation"));
const WithErrorBoundary_1 = require("../../../common/components/ErrorHandling/WithErrorBoundary");
const CustomManifestsPage_1 = require("../clusterConfiguration/manifestsConfiguration/CustomManifestsPage");
const react_redux_1 = require("react-redux");
const selectors_1 = require("../../store/slices/current-cluster/selectors");
const getInitialFormStateProps = () => {
    return {
        isValid: true,
        isSubmitting: false,
        isAutoSaveRunning: false,
        errors: {},
        touched: {},
        isEmpty: true,
    };
};
const CustomManifestStep = ({ cluster }) => {
    const clusterWizardContext = (0, ClusterWizardContext_1.useClusterWizardContext)();
    const { isViewerMode } = (0, react_redux_1.useSelector)(selectors_1.selectCurrentClusterPermissionsState);
    const { alerts } = (0, common_1.useAlerts)();
    const [formState, setFormStateProps] = react_1.default.useState(getInitialFormStateProps());
    const onFormStateChange = (formState) => {
        if (!isViewerMode) {
            setFormStateProps(formState);
        }
    };
    const isNextDisabled = formState.isAutoSaveRunning || !formState.isValid || !!alerts.length || formState.isSubmitting;
    const errorFields = (0, common_1.getFormikErrorFields)(formState.errors, formState.touched);
    const footer = (react_1.default.createElement(ClusterWizardFooter_1.default, { cluster: cluster, alertTitle: "Custom manifests configuration contains missing or invalid fields", alertContent: null, errorFields: errorFields, isSubmitting: formState.isSubmitting, onNext: () => clusterWizardContext.moveNext(), onBack: () => clusterWizardContext.moveBack(), isNextDisabled: isNextDisabled, isBackDisabled: formState.isSubmitting || formState.isAutoSaveRunning }));
    return (react_1.default.createElement(common_1.ClusterWizardStep, { navigation: react_1.default.createElement(ClusterWizardNavigation_1.default, { cluster: cluster }), footer: footer },
        react_1.default.createElement(WithErrorBoundary_1.WithErrorBoundary, { title: "Failed to load Custom manifests step" },
            react_1.default.createElement(CustomManifestsPage_1.CustomManifestsPage, { cluster, onFormStateChange }))));
};
exports.default = CustomManifestStep;
//# sourceMappingURL=CustomManifestStep.js.map