"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const react_1 = tslib_1.__importDefault(require("react"));
const react_core_1 = require("@patternfly/react-core");
const formik_1 = require("formik");
const ui_1 = require("../../../../../common/components/ui");
const constants_1 = require("../../../../../common/config/constants");
const use_translation_wrapper_1 = require("../../../../../common/hooks/use-translation-wrapper");
const AdvancedNetworkFields = ({ isClusterCIDRIPv6 }) => {
    const { setFieldValue, values } = (0, formik_1.useFormikContext)();
    const clusterNetworkCidrPrefix = parseInt((values.clusterNetworkCidr || '').split('/')[1]) || 1;
    const { t } = (0, use_translation_wrapper_1.useTranslation)();
    const formatClusterNetworkHostPrefix = (e) => {
        if (isNaN(parseInt(e.target.value))) {
            setFieldValue('clusterNetworkHostPrefix', clusterNetworkCidrPrefix);
        }
    };
    const clusterNetworkHostPrefixHelperText = isClusterCIDRIPv6
        ? t('ai:The subnet prefix length to assign to each individual node. For example, if Cluster Network Host Prefix is set to 116, then each node is assigned a /116 subnet out of the given cidr (clusterNetworkCIDR), which allows for 4,094 (2^(128 - 116) - 2) pod IPs addresses. If you are required to provide access to nodes from an external network, configure load balancers and routers to manage the traffic.')
        : t('ai:The subnet prefix length to assign to each individual node. For example, if Cluster Network Host Prefix is set to 23, then each node is assigned a /23 subnet out of the given cidr (clusterNetworkCIDR), which allows for 510 (2^(32 - 23) - 2) pod IPs addresses. If you are required to provide access to nodes from an external network, configure load balancers and routers to manage the traffic.');
    return (react_1.default.createElement(react_core_1.Grid, { hasGutter: true },
        react_1.default.createElement(ui_1.InputField, { name: "clusterNetworkCidr", label: t('ai:Cluster network CIDR'), helperText: t('ai:IP address block from which Pod IPs are allocated This block must not overlap with existing physical networks. These IP addresses are used for the Pod network, and if you need to access the Pods from an external network, configure load balancers and routers to manage the traffic.'), isRequired: true }),
        react_1.default.createElement(ui_1.InputField, { name: "clusterNetworkHostPrefix", label: t('ai:Cluster network host prefix'), type: react_core_1.TextInputTypes.number, min: clusterNetworkCidrPrefix, max: isClusterCIDRIPv6 ? constants_1.PREFIX_MAX_RESTRICTION.IPv6 : constants_1.PREFIX_MAX_RESTRICTION.IPv4, onBlur: (e) => formatClusterNetworkHostPrefix(e), helperText: clusterNetworkHostPrefixHelperText, isRequired: true }),
        react_1.default.createElement(ui_1.InputField, { name: "serviceNetworkCidr", label: t('ai:Service network CIDR'), helperText: t('ai:The IP address pool to use for service IP addresses. You can enter only one IP address pool. If you need to access the services from an external network, configure load balancers and routers to manage the traffic.'), isRequired: true })));
};
exports.default = AdvancedNetworkFields;
//# sourceMappingURL=AdvancedNetworkFields.js.map