"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DiscoveryImageConfigForm = exports.StaticIPInfo = void 0;
const tslib_1 = require("tslib");
const react_1 = tslib_1.__importDefault(require("react"));
const Yup = tslib_1.__importStar(require("yup"));
const react_core_1 = require("@patternfly/react-core");
const external_link_alt_icon_1 = require("@patternfly/react-icons/dist/js/icons/external-link-alt-icon");
const formik_1 = require("formik");
const ui_1 = require("../../../common/components/ui");
const validationSchemas_1 = require("../../validationSchemas");
const ProxyFields_1 = tslib_1.__importDefault(require("./ProxyFields"));
const UploadSSH_1 = tslib_1.__importDefault(require("./UploadSSH"));
const DiscoveryImageTypeControlGroup_1 = tslib_1.__importDefault(require("./DiscoveryImageTypeControlGroup"));
const docs_links_1 = require("../../config/docs_links");
const use_translation_wrapper_1 = require("../../hooks/use-translation-wrapper");
const StaticIPInfo = ({ docVersion }) => {
    const { t } = (0, use_translation_wrapper_1.useTranslation)();
    return (react_1.default.createElement(react_core_1.Alert, { title: t('ai:To use static network configuration, follow the steps listed in the documentation.'), isInline: true, variant: "info" },
        react_1.default.createElement(react_core_1.Button, { variant: "link", icon: react_1.default.createElement(external_link_alt_icon_1.ExternalLinkAltIcon, null), iconPosition: "right", isInline: true, onClick: () => window.open((0, docs_links_1.getOCPStaticIPDocLink)(docVersion), '_blank', 'noopener') }, t('ai:View documentation'))));
};
exports.StaticIPInfo = StaticIPInfo;
const getValidationSchema = (allowEmpty, t) => Yup.lazy((values) => Yup.object().shape({
    sshPublicKey: (0, validationSchemas_1.sshPublicKeyValidationSchema)(t),
    httpProxy: (0, validationSchemas_1.httpProxyValidationSchema)({ values, pairValueName: 'httpsProxy', allowEmpty, t }),
    httpsProxy: (0, validationSchemas_1.httpProxyValidationSchema)({ values, pairValueName: 'httpProxy', allowEmpty, t }), // share the schema, httpS is currently not supported
    noProxy: (0, validationSchemas_1.noProxyValidationSchema)(t),
}));
const DiscoveryImageConfigForm = ({ handleSubmit, onCancel, sshPublicKey, httpProxy, httpsProxy, noProxy, imageType, hideDiscoveryImageType, hasDHCP, isIPXE, allowEmpty, docVersion, }) => {
    const initialValues = {
        sshPublicKey: sshPublicKey || '',
        httpProxy: httpProxy || '',
        httpsProxy: httpsProxy || '',
        noProxy: noProxy || '',
        enableProxy: !!(httpProxy || httpsProxy || noProxy),
        imageType: imageType || 'minimal-iso',
    };
    const { t } = (0, use_translation_wrapper_1.useTranslation)();
    return (react_1.default.createElement(formik_1.Formik, { initialValues: initialValues, initialStatus: { error: null }, validationSchema: getValidationSchema(!!allowEmpty, t), onSubmit: handleSubmit }, ({ submitForm, isSubmitting, status }) => {
        return (react_1.default.createElement(react_1.default.Fragment, null,
            react_1.default.createElement(react_core_1.ModalBody, null,
                react_1.default.createElement(react_core_1.Stack, { hasGutter: true },
                    hasDHCP === false && (react_1.default.createElement(react_core_1.StackItem, null,
                        react_1.default.createElement(exports.StaticIPInfo, { docVersion: docVersion }))),
                    react_1.default.createElement(react_core_1.StackItem, null,
                        react_1.default.createElement(react_core_1.Form, null,
                            !hideDiscoveryImageType && react_1.default.createElement(DiscoveryImageTypeControlGroup_1.default, null),
                            react_1.default.createElement(ui_1.AlertFormikError, { status: status }),
                            react_1.default.createElement(react_core_1.Alert, { variant: react_core_1.AlertVariant.info, isInline: true, title: isIPXE
                                    ? t('ai:To add hosts to the cluster, generate iPXE script.')
                                    : t('ai:To add hosts to the cluster, generate a Discovery ISO.') }),
                            react_1.default.createElement(UploadSSH_1.default, null),
                            react_1.default.createElement(ProxyFields_1.default, null))))),
            react_1.default.createElement(react_core_1.ModalFooter, null,
                react_1.default.createElement(react_core_1.Button
                // eslint-disable-next-line @typescript-eslint/no-misused-promises
                , { 
                    // eslint-disable-next-line @typescript-eslint/no-misused-promises
                    onClick: submitForm, isDisabled: isSubmitting, isLoading: isSubmitting }, isSubmitting
                    ? t('ai:Generating')
                    : isIPXE
                        ? t('ai:Generate script file')
                        : t('ai:Generate Discovery ISO')),
                react_1.default.createElement(react_core_1.Button, { key: "cancel", variant: "link", onClick: onCancel }, t('ai:Cancel')))));
    }));
};
exports.DiscoveryImageConfigForm = DiscoveryImageConfigForm;
//# sourceMappingURL=DiscoveryImageConfigForm.js.map