"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const React = tslib_1.__importStar(require("react"));
const react_core_1 = require("@patternfly/react-core");
const formik_1 = require("formik");
const common_1 = require("../../../../common");
const use_translation_wrapper_1 = require("../../../../common/hooks/use-translation-wrapper");
const helpers_1 = require("../../helpers");
const NodePoolAgentsForm_1 = tslib_1.__importDefault(require("../forms/NodePoolAgentsForm"));
const utils_1 = require("../utils");
const NodePoolForm = ({ agents, nodePool, hostedCluster, agentMachines }) => {
    var _a, _b;
    const { t } = (0, use_translation_wrapper_1.useTranslation)();
    const { values } = (0, formik_1.useFormikContext)();
    const isEdit = !!nodePool && !!agentMachines;
    let maxAgents = 0;
    const availableAgents = (0, helpers_1.getAgentsForSelection)(agents).filter((agent) => values.agentLabels.every(({ key, value }) => { var _a, _b; return ((_b = (_a = agent.metadata) === null || _a === void 0 ? void 0 : _a.labels) === null || _b === void 0 ? void 0 : _b[key]) === value; }) &&
        !agent.spec.clusterDeploymentName);
    const ocpVersion = (0, helpers_1.getVersionFromReleaseString)(hostedCluster.spec.release.image);
    if (isEdit) {
        const nodePoolAgents = (0, utils_1.getNodepoolAgents)(nodePool, agents, agentMachines, hostedCluster);
        maxAgents =
            nodePoolAgents.length +
                availableAgents.filter((agent) => !nodePoolAgents.find((a) => { var _a, _b; return ((_a = a.metadata) === null || _a === void 0 ? void 0 : _a.uid) === ((_b = agent.metadata) === null || _b === void 0 ? void 0 : _b.uid); })).length;
    }
    else {
        maxAgents += availableAgents.length;
    }
    return (React.createElement(react_core_1.Form, null,
        React.createElement(react_core_1.Grid, { hasGutter: true },
            React.createElement(react_core_1.GridItem, null,
                React.createElement(react_core_1.DescriptionList, { isHorizontal: true },
                    React.createElement(react_core_1.DescriptionListGroup, null,
                        React.createElement(react_core_1.DescriptionListTerm, null, t('ai:Host namespace')),
                        React.createElement(react_core_1.DescriptionListDescription, null, (_a = hostedCluster.spec.platform.agent) === null || _a === void 0 ? void 0 : _a.agentNamespace)))),
            React.createElement(react_core_1.GridItem, null, nodePool ? (React.createElement(react_core_1.DescriptionList, { isHorizontal: true },
                React.createElement(react_core_1.DescriptionListGroup, null,
                    React.createElement(react_core_1.DescriptionListTerm, null, t('ai:Nodepool')),
                    React.createElement(react_core_1.DescriptionListDescription, null, (_b = nodePool.metadata) === null || _b === void 0 ? void 0 : _b.name)))) : (React.createElement(common_1.InputField, { name: "nodePoolName", isRequired: true, label: t('ai:Nodepool name') }))),
            React.createElement(react_core_1.GridItem, null,
                React.createElement(NodePoolAgentsForm_1.default, { agents: agents, countName: "count", labelName: "agentLabels", autoscalingName: `autoscaling`, useAutoscalingName: `useAutoscaling`, maxAgents: maxAgents, isEdit: isEdit })),
            React.createElement(react_core_1.GridItem, null,
                React.createElement(react_core_1.DescriptionList, { isHorizontal: true, horizontalTermWidthModifier: { default: '17ch' } },
                    React.createElement(react_core_1.DescriptionListGroup, null,
                        React.createElement(react_core_1.DescriptionListTerm, null, t('ai:OpenShift version')),
                        React.createElement(react_core_1.DescriptionListDescription, null, ocpVersion || hostedCluster.spec.release.image)))))));
};
exports.default = NodePoolForm;
//# sourceMappingURL=NodePoolForm.js.map