"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MinimalHWRequirementsModal = exports.getHWRequirements = void 0;
const tslib_1 = require("tslib");
const React = tslib_1.__importStar(require("react"));
const react_core_1 = require("@patternfly/react-core");
const info_circle_icon_1 = require("@patternfly/react-icons/dist/js/icons/info-circle-icon");
const HostRequirements_1 = tslib_1.__importDefault(require("../../../common/components/hosts/HostRequirements"));
const use_translation_wrapper_1 = require("../../../common/hooks/use-translation-wrapper");
const getHWRequirements = (aiConfigMap) => {
    var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
    let hwRequirements;
    try {
        const hwData = JSON.parse(((_a = aiConfigMap.data) === null || _a === void 0 ? void 0 : _a.HW_VALIDATOR_REQUIREMENTS) || '[]');
        hwRequirements = hwData.find((req) => req.version === 'default');
    }
    catch (_l) {
        // console.error('Failed to parse hw requirements config map');
        hwRequirements = undefined;
    }
    return {
        master: {
            cpuCores: (_b = hwRequirements === null || hwRequirements === void 0 ? void 0 : hwRequirements.master) === null || _b === void 0 ? void 0 : _b.cpu_cores,
            ramMib: (_c = hwRequirements === null || hwRequirements === void 0 ? void 0 : hwRequirements.master) === null || _c === void 0 ? void 0 : _c.ram_mib,
            diskSizeGb: (_d = hwRequirements === null || hwRequirements === void 0 ? void 0 : hwRequirements.master) === null || _d === void 0 ? void 0 : _d.disk_size_gb,
        },
        worker: {
            cpuCores: (_e = hwRequirements === null || hwRequirements === void 0 ? void 0 : hwRequirements.worker) === null || _e === void 0 ? void 0 : _e.cpu_cores,
            ramMib: (_f = hwRequirements === null || hwRequirements === void 0 ? void 0 : hwRequirements.worker) === null || _f === void 0 ? void 0 : _f.ram_mib,
            diskSizeGb: (_g = hwRequirements === null || hwRequirements === void 0 ? void 0 : hwRequirements.worker) === null || _g === void 0 ? void 0 : _g.disk_size_gb,
        },
        sno: {
            cpuCores: (_h = hwRequirements === null || hwRequirements === void 0 ? void 0 : hwRequirements.sno) === null || _h === void 0 ? void 0 : _h.cpu_cores,
            ramMib: (_j = hwRequirements === null || hwRequirements === void 0 ? void 0 : hwRequirements.sno) === null || _j === void 0 ? void 0 : _j.ram_mib,
            diskSizeGb: (_k = hwRequirements === null || hwRequirements === void 0 ? void 0 : hwRequirements.sno) === null || _k === void 0 ? void 0 : _k.disk_size_gb,
        },
    };
};
exports.getHWRequirements = getHWRequirements;
const MinimalHWRequirements = ({ aiConfigMap, isSNOCluster, }) => {
    const [isHostRequirementsOpen, setHostRequirementsOpen] = React.useState(false);
    const { t } = (0, use_translation_wrapper_1.useTranslation)();
    return (React.createElement(React.Fragment, null,
        React.createElement(react_core_1.Button, { variant: react_core_1.ButtonVariant.link, onClick: () => setHostRequirementsOpen(true), isInline: true, className: "host-requirements-link" },
            React.createElement(react_core_1.Icon, { status: "warning", size: "sm" },
                React.createElement(info_circle_icon_1.InfoCircleIcon, null)),
            "\u00A0",
            t('ai:Minimum hardware requirements')),
        React.createElement(exports.MinimalHWRequirementsModal, { isOpen: isHostRequirementsOpen, onClose: () => setHostRequirementsOpen(false), aiConfigMap: aiConfigMap, isSNOCluster: isSNOCluster })));
};
const MinimalHWRequirementsModal = ({ isOpen, aiConfigMap, isSNOCluster, onClose, }) => {
    const { t } = (0, use_translation_wrapper_1.useTranslation)();
    return (React.createElement(react_core_1.Modal, { isOpen: isOpen, onClose: onClose, variant: react_core_1.ModalVariant.medium },
        React.createElement(react_core_1.ModalHeader, { title: t('ai:Minimum hardware requirements') }),
        React.createElement(react_core_1.ModalBody, null,
            React.createElement(HostRequirements_1.default, Object.assign({}, (0, exports.getHWRequirements)(aiConfigMap), { isSNOCluster: isSNOCluster }))),
        React.createElement(react_core_1.ModalFooter, null,
            React.createElement(react_core_1.Button, { key: "close", variant: react_core_1.ButtonVariant.primary, onClick: onClose }, t('ai:Close')))));
};
exports.MinimalHWRequirementsModal = MinimalHWRequirementsModal;
exports.default = MinimalHWRequirements;
//# sourceMappingURL=MinimalHWRequirements.js.map