"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const React = tslib_1.__importStar(require("react"));
const Yup = tslib_1.__importStar(require("yup"));
const formik_1 = require("formik");
const noop_js_1 = tslib_1.__importDefault(require("lodash-es/noop.js"));
const react_core_1 = require("@patternfly/react-core");
const HostsForm_1 = tslib_1.__importDefault(require("./HostsForm"));
const use_translation_wrapper_1 = require("../../../../../common/hooks/use-translation-wrapper");
const validationSchema = (clusterName, nodePools, t) => Yup.lazy((values) => Yup.object().shape({
    agentNamespace: Yup.string().required(t('ai:Required field')),
    nodePools: Yup.array().of(Yup.object()
        .shape({
        nodePoolName: Yup.string()
            .required(t('ai:Required field'))
            .test(t('ai:Must be unique'), t('ai:Must be unique'), (value) => {
            if (!value) {
                return true;
            }
            return (values.nodePools.filter(({ nodePoolName }) => nodePoolName === value).length ===
                1 &&
                !nodePools.some(({ metadata }) => (metadata === null || metadata === void 0 ? void 0 : metadata.name) === value && (metadata === null || metadata === void 0 ? void 0 : metadata.namespace) === clusterName));
        }),
        clusterName: Yup.string().required(t('ai:Required field')),
        count: Yup.number(),
        releaseImage: Yup.string().required(t('ai:Required field')),
        autoscaling: Yup.object().shape({
            minReplicas: Yup.number().min(1, t('ai:Must be at least 1')),
            maxReplicas: Yup.number().min(1, t('ai:Must be at least 1')),
        }),
    })
        .required(t('ai:Required field'))),
}));
const HostsStep = ({ formRef, onValuesChanged, infraEnvs, agents, clusterName, initInfraEnv, initNodePools, initReleaseImage, nodePools, controllerAvailabilityPolicy, infrastructureAvailabilityPolicy, olmCatalogPlacement, }) => {
    var _a, _b;
    const { t } = (0, use_translation_wrapper_1.useTranslation)();
    return (React.createElement(react_core_1.Stack, { hasGutter: true },
        React.createElement(react_core_1.StackItem, null, t('ai:Define the quantity of worker nodes and nodepools to create for your cluster. Additional worker nodes and nodepools can be added after the cluster is created.')),
        React.createElement(react_core_1.StackItem, null,
            React.createElement(formik_1.Formik, { initialValues: {
                    controllerAvailabilityPolicy: controllerAvailabilityPolicy || 'HighlyAvailable',
                    infrastructureAvailabilityPolicy: infrastructureAvailabilityPolicy || 'HighlyAvailable',
                    olmCatalogPlacement: olmCatalogPlacement || 'management',
                    agentNamespace: initInfraEnv || ((_b = (_a = infraEnvs[0]) === null || _a === void 0 ? void 0 : _a.metadata) === null || _b === void 0 ? void 0 : _b.namespace) || '',
                    nodePools: initNodePools || [
                        {
                            nodePoolName: `nodepool-${clusterName}-1`,
                            count: 1,
                            agentLabels: [],
                            releaseImage: initReleaseImage,
                            clusterName,
                            useAutoscaling: false,
                            autoscaling: {
                                minReplicas: 1,
                                maxReplicas: 1,
                            },
                        },
                    ],
                }, validationSchema: validationSchema(clusterName, nodePools, t), innerRef: formRef, onSubmit: noop_js_1.default },
                React.createElement(HostsForm_1.default, { onValuesChanged: onValuesChanged, infraEnvs: infraEnvs, agents: agents, clusterName: clusterName, initReleaseImage: initReleaseImage })))));
};
exports.default = HostsStep;
//# sourceMappingURL=HostsStep.js.map