"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const formik_1 = require("formik");
const noop_js_1 = tslib_1.__importDefault(require("lodash-es/noop.js"));
const React = tslib_1.__importStar(require("react"));
const Yup = tslib_1.__importStar(require("yup"));
const common_1 = require("../../../../../common");
const use_translation_wrapper_1 = require("../../../../../common/hooks/use-translation-wrapper");
const useSupportedOCPVersions_1 = require("../../hooks/useSupportedOCPVersions");
const DetailsForm_1 = tslib_1.__importDefault(require("./DetailsForm"));
const useDetailsFormik = ({ ocpVersions, usedClusterNames, initPullSecret = '', initBaseDomain = '', }) => {
    const { t } = (0, use_translation_wrapper_1.useTranslation)();
    const initialValues = React.useMemo(() => ({
        name: '',
        openshiftVersion: (0, common_1.getDefaultOpenShiftVersion)(ocpVersions),
        pullSecret: initPullSecret,
        baseDnsDomain: initBaseDomain,
        customOpenshiftSelect: null,
    }), []);
    const validationSchema = React.useMemo(() => Yup.object({
        name: (0, common_1.nameValidationSchema)(t, usedClusterNames),
        baseDnsDomain: (0, common_1.dnsNameValidationSchema)(t).required(t('ai:Required field')),
        pullSecret: (0, common_1.pullSecretValidationSchema)(t).required(t('ai:Required field')),
    }), [usedClusterNames, t]);
    return [initialValues, validationSchema];
};
const DetailsStep = ({ usedClusterNames, clusterImages, onValuesChanged, extensionAfter, formRef, initBaseDomain, initPullSecret, supportedVersionsCM, }) => {
    const ocpVersions = (0, useSupportedOCPVersions_1.useSupportedOCPVersions)(clusterImages, supportedVersionsCM);
    const allVersions = (0, useSupportedOCPVersions_1.useSupportedOCPVersions)(clusterImages, supportedVersionsCM, true);
    const [initialValues, validationSchema] = useDetailsFormik({
        ocpVersions,
        usedClusterNames,
        initPullSecret,
        initBaseDomain,
    });
    return (React.createElement(formik_1.Formik, { initialValues: initialValues, validationSchema: validationSchema, innerRef: formRef, onSubmit: noop_js_1.default },
        React.createElement(DetailsForm_1.default, { onValuesChanged: onValuesChanged, ocpVersions: ocpVersions, allVersions: allVersions, extensionAfter: extensionAfter })));
};
exports.default = DetailsStep;
//# sourceMappingURL=DetailsStep.js.map