"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 formik_1 = require("formik");
const common_1 = require("../../../common");
const ClusterWizardFooter_1 = tslib_1.__importDefault(require("./ClusterWizardFooter"));
const ClusterWizardContext_1 = require("./ClusterWizardContext");
const ClusterWizardNavigation_1 = tslib_1.__importDefault(require("./ClusterWizardNavigation"));
const wizardTransition_1 = require("./wizardTransition");
const HostsStorageTable_1 = tslib_1.__importDefault(require("../hosts/HostsStorageTable"));
const StorageForm = ({ cluster }) => {
    const { alerts } = (0, common_1.useAlerts)();
    const clusterWizardContext = (0, ClusterWizardContext_1.useClusterWizardContext)();
    const { isSubmitting, touched, errors } = (0, formik_1.useFormikContext)();
    const isAutoSaveRunning = (0, common_1.useFormikAutoSave)();
    const errorFields = (0, common_1.getFormikErrorFields)(errors, touched);
    const isNextDisabled = !(0, wizardTransition_1.canNextStorage)({ cluster }) || isAutoSaveRunning || !!alerts.length || isSubmitting;
    const footer = (react_1.default.createElement(ClusterWizardFooter_1.default, { cluster: cluster, errorFields: errorFields, isSubmitting: isSubmitting, isNextDisabled: isNextDisabled, onNext: () => clusterWizardContext.moveNext(), onBack: () => clusterWizardContext.moveBack(), isBackDisabled: isSubmitting || 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(react_core_1.StackItem, null,
            react_1.default.createElement(common_1.ClusterWizardStepHeader, null, "Storage")),
        react_1.default.createElement(react_core_1.StackItem, null,
            react_1.default.createElement(HostsStorageTable_1.default, { cluster: cluster })),
        react_1.default.createElement(common_1.FormikAutoSave, null)));
};
const Storage = ({ cluster }) => {
    const { clearAlerts } = (0, common_1.useAlerts)();
    const initialValues = react_1.default.useMemo(() => (0, common_1.getStorageInitialValues)(), []);
    const handleSubmit = () => {
        clearAlerts();
    };
    return (react_1.default.createElement(formik_1.Formik, { onSubmit: handleSubmit, initialValues: initialValues },
        react_1.default.createElement(StorageForm, { cluster: cluster })));
};
exports.default = Storage;
//# sourceMappingURL=Storage.js.map