"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ProxyInputFields = 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");
require("./ProxyFields.css");
const react_i18next_1 = require("react-i18next");
const ProxyInputFields = () => {
    var _a, _b;
    const { setFieldValue, values } = (0, formik_1.useFormikContext)();
    const onNoProxyBlur = () => {
        if (values.noProxy) {
            setFieldValue('noProxy', (0, ui_1.trimCommaSeparatedList)(values.noProxy));
        }
    };
    const { t } = (0, use_translation_wrapper_1.useTranslation)();
    const hasHttp = !!((_a = values.httpProxy) === null || _a === void 0 ? void 0 : _a.trim());
    const hasHttps = !!((_b = values.httpsProxy) === null || _b === void 0 ? void 0 : _b.trim());
    return (react_1.default.createElement(react_core_1.Grid, { hasGutter: true },
        react_1.default.createElement(ui_1.InputField, { label: react_1.default.createElement(react_1.default.Fragment, null,
                t('ai:HTTP proxy URL'),
                ' ',
                react_1.default.createElement(ui_1.PopoverIcon, { bodyContent: t('ai:The HTTP proxy URL that agents should use to access the discovery service.') })), name: "httpProxy", placeholder: "http://<user>:<password>@<ipaddr>:<port>", isRequired: values.enableProxy && !hasHttps, helperText: react_1.default.createElement("div", null,
                react_1.default.createElement(react_i18next_1.Trans, { t: t, components: { bold: react_1.default.createElement("span", { className: "pf-v6-u-font-weight-bold" }) }, i18nKey: "ai:URL must start with <bold>http</bold>." })) }),
        react_1.default.createElement(ui_1.InputField, { label: react_1.default.createElement(react_1.default.Fragment, null,
                t('ai:HTTPS proxy URL'),
                ' ',
                react_1.default.createElement(ui_1.PopoverIcon, { bodyContent: t("ai:Specify the HTTPS proxy that agents should use to access the discovery service. If you don't provide a value, your HTTP proxy URL will be used by default for both HTTP and HTTPS connections.") })), name: "httpsProxy", placeholder: "http://<user>:<password>@<ipaddr>:<port>", isRequired: values.enableProxy && !hasHttp, helperText: react_1.default.createElement("div", null,
                react_1.default.createElement(react_i18next_1.Trans, { t: t, components: { bold: react_1.default.createElement("span", { className: "pf-v6-u-font-weight-bold" }) }, i18nKey: "ai:URL must start with <bold>http</bold> (https schemes are not currently supported)." })) }),
        react_1.default.createElement(ui_1.InputField, { label: react_1.default.createElement(react_1.default.Fragment, null,
                t('ai:No proxy domains'),
                ' ',
                react_1.default.createElement(ui_1.PopoverIcon, { bodyContent: t('ai:Exclude destination domain names, IP addresses, or other network CIDRs from proxying by adding them to this comma-separated list.') })), name: "noProxy", placeholder: "one.domain.com,second.domain.com", helperText: react_1.default.createElement("div", null,
                react_1.default.createElement(react_i18next_1.Trans, { t: t, components: { bold: react_1.default.createElement("span", { className: "pf-v6-u-font-weight-bold" }) }, i18nKey: "ai:Use a comma to separate each listed domain. Preface a domain with <bold>.</bold> to include its subdomains. Use <bold>*</bold> to bypass the proxy for all destinations." })), onBlur: onNoProxyBlur })));
};
exports.ProxyInputFields = ProxyInputFields;
const ProxyFields = () => {
    const { setFieldValue, values, initialValues } = (0, formik_1.useFormikContext)();
    const resetProxy = (isNewlyChecked) => {
        if (isNewlyChecked) {
            setFieldValue('httpProxy', initialValues.httpProxy);
            setFieldValue('httpsProxy', initialValues.httpsProxy);
            setFieldValue('noProxy', initialValues.noProxy);
        }
        else {
            setFieldValue('httpProxy', '');
            setFieldValue('httpsProxy', '');
            setFieldValue('noProxy', '');
        }
    };
    const { t } = (0, use_translation_wrapper_1.useTranslation)();
    // https://docs.openshift.com/container-platform/4.6/networking/enable-cluster-wide-proxy.html
    return (react_1.default.createElement(react_1.default.Fragment, null,
        react_1.default.createElement(ui_1.CheckboxField, { label: t('ai:Show proxy settings'), name: "enableProxy", className: "ai-proxy-fields", helperText: react_1.default.createElement("p", null, t('ai:If hosts are behind a firewall that requires the use of a proxy, provide additional information about the proxy.')), onChange: (value) => resetProxy(value), body: values.enableProxy && react_1.default.createElement(exports.ProxyInputFields, null) })));
};
exports.default = ProxyFields;
//# sourceMappingURL=ProxyFields.js.map