"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const react_core_1 = require("@patternfly/react-core");
const React = tslib_1.__importStar(require("react"));
const common_1 = require("../../../../common");
const use_translation_wrapper_1 = require("../../../../common/hooks/use-translation-wrapper");
const LabelsSelector_1 = require("../../ClusterDeployment/LabelsSelector");
const formik_1 = require("formik");
const NodePoolAgentsForm = ({ agents, labelName, countName, autoscalingName, maxAgents, useAutoscalingName, isEdit = false, }) => {
    const { t } = (0, use_translation_wrapper_1.useTranslation)();
    const [{ value: count }] = (0, formik_1.useField)(countName);
    const [{ value: minValue }] = (0, formik_1.useField)(`${autoscalingName}.minReplicas`);
    const [{ value: maxValue }] = (0, formik_1.useField)(`${autoscalingName}.maxReplicas`);
    const [{ value: useAutoscalingValue }] = (0, formik_1.useField)(useAutoscalingName);
    const helperText = (React.createElement(React.Fragment, null,
        t('ai:Maximum availability {{maxAgents}}', { maxAgents }),
        ' ',
        React.createElement(common_1.PopoverIcon, { bodyContent: t('ai:Maximum availability is based on the number of hosts available in a given namespace. The number changes dynamically depending on the filtering labels added above.') })));
    return (React.createElement(react_core_1.Grid, { hasGutter: true },
        !isEdit && (React.createElement(react_core_1.GridItem, null,
            React.createElement(LabelsSelector_1.LabelSelectorGroup, { agents: agents, name: labelName }))),
        React.createElement(react_core_1.GridItem, null,
            React.createElement(common_1.CheckboxField, { name: useAutoscalingName, label: t('ai:Use autoscaling') })),
        useAutoscalingValue ? (React.createElement(React.Fragment, null,
            React.createElement(react_core_1.GridItem, null,
                React.createElement(common_1.NumberInputField, { name: `${autoscalingName}.minReplicas`, label: t('ai:Minimum number of hosts'), isRequired: true, minValue: 1, maxValue: maxValue })),
            React.createElement(react_core_1.GridItem, null,
                React.createElement(common_1.NumberInputField, { name: `${autoscalingName}.maxReplicas`, label: t('ai:Maximum number of hosts'), isRequired: true, minValue: minValue || 1, helperText: helperText })))) : (React.createElement(React.Fragment, null,
            React.createElement(react_core_1.GridItem, null,
                React.createElement(common_1.NumberInputField, { label: t('ai:Number of hosts'), idPostfix: "count", name: countName, isRequired: true, minValue: 0, helperText: helperText })))),
        (useAutoscalingValue ? maxValue : count) > maxAgents && (React.createElement(react_core_1.GridItem, null,
            React.createElement(react_core_1.Alert, { isInline: true, variant: react_core_1.AlertVariant.warning, title: t('ai:Host count exceeds the current number of available hosts.') },
                React.createElement(react_core_1.Content, null, t('ai:Scale down the nodepool or make more hosts available.')))))));
};
exports.default = NodePoolAgentsForm;
//# sourceMappingURL=NodePoolAgentsForm.js.map