"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CertificateInputFields = exports.CertificateFieldsHelperText = void 0;
const tslib_1 = require("tslib");
const react_1 = tslib_1.__importDefault(require("react"));
const formik_1 = require("formik");
const react_core_1 = require("@patternfly/react-core");
const ui_1 = require("../ui");
const use_translation_wrapper_1 = require("../../hooks/use-translation-wrapper");
const CertificatesUploadField_1 = tslib_1.__importDefault(require("../ui/formik/CertificatesUploadField"));
require("./CertificateFields.css");
const FIELD_NAME = 'trustBundle';
const CertificateFieldsHelperText = ({ fieldId = FIELD_NAME }) => {
    const { t } = (0, use_translation_wrapper_1.useTranslation)();
    return (react_1.default.createElement(react_core_1.FormGroup, null,
        react_1.default.createElement(react_core_1.FormHelperText, null,
            react_1.default.createElement(react_core_1.HelperText, { id: fieldId },
                react_1.default.createElement(react_core_1.HelperTextItem, { "data-testid": "certificate-fields-helper-text" }, t('ai:Paste in 1 or more PEM formatted certificates that you want the cluster to trust.'))))));
};
exports.CertificateFieldsHelperText = CertificateFieldsHelperText;
const CertificateInputFields = () => {
    const [{ name, value }, , { setValue }] = (0, formik_1.useField)(FIELD_NAME);
    const { t } = (0, use_translation_wrapper_1.useTranslation)();
    return (react_1.default.createElement(react_core_1.Grid, { hasGutter: true },
        react_1.default.createElement(CertificatesUploadField_1.default, { label: react_1.default.createElement(react_1.default.Fragment, null,
                t('ai:Additional certificates'),
                ' ',
                react_1.default.createElement(ui_1.PopoverIcon, { bodyContent: t('ai:You can upload additional trusted certificates in PEM-encoded X.509 format if the cluster hosts are in a network with a re-encrypting (MITM) proxy or the cluster needs to trust certificates for other purposes (for example, container image registries).') })), name: name, helperText: react_1.default.createElement(exports.CertificateFieldsHelperText, null), idPostfix: "certificates", onBlur: () => value && setValue(value) })));
};
exports.CertificateInputFields = CertificateInputFields;
const CertificateFields = () => {
    const { setFieldValue, values, initialValues } = (0, formik_1.useFormikContext)();
    const resetCertificate = (isNewlyChecked) => {
        if (isNewlyChecked) {
            setFieldValue(FIELD_NAME, initialValues.trustBundle);
        }
        else {
            setFieldValue(FIELD_NAME, '');
        }
    };
    const { t } = (0, use_translation_wrapper_1.useTranslation)();
    return (react_1.default.createElement(react_1.default.Fragment, null,
        react_1.default.createElement(ui_1.CheckboxField, { label: t('ai:Configure cluster-wide trusted certificates'), name: "enableCertificate", helperText: react_1.default.createElement("p", null, t('ai:If the cluster hosts are in a network with a re-encrypting (MITM) proxy or the cluster needs to trust certificates for other purposes (e.g. container image registries).')), onChange: (value) => resetCertificate(value), body: values.enableCertificate && react_1.default.createElement(exports.CertificateInputFields, null), className: "ai-certificate-fields" })));
};
exports.default = CertificateFields;
//# sourceMappingURL=CertificateFields.js.map