"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ExternalPlatformsDropdown = exports.getPlatforms = void 0;
const tslib_1 = require("tslib");
const React = tslib_1.__importStar(require("react"));
const ui_1 = require("../ui");
const hooks_1 = require("../../hooks");
const react_core_1 = require("@patternfly/react-core");
const formik_1 = require("formik");
const getPlatforms = (t) => ({
    none: t('ai:No platform integration'),
    baremetal: t('ai:No platform integration'),
    nutanix: t('ai:Nutanix'),
    vsphere: t('ai:vSphere'),
    external: t('ai:External cloud provider'),
});
exports.getPlatforms = getPlatforms;
const ExternalPlatformsDropdown = ({ isDisabled }) => {
    const [isOpen, setIsOpen] = React.useState(false);
    const [{ value }, , { setValue }] = (0, formik_1.useField)('platform');
    const { setFieldValue, values } = (0, formik_1.useFormikContext)();
    const { t } = (0, hooks_1.useTranslation)();
    const platforms = (0, exports.getPlatforms)(t);
    const isSNO = values.controlPlaneCount === 1;
    const options = Object.entries(platforms)
        .filter(([key]) => {
        if (isSNO) {
            return key === 'none' || key === 'vsphere' || key === 'external';
        }
        else {
            return key !== 'none';
        }
    })
        .map(([platform, label]) => (React.createElement(react_core_1.DropdownItem, { key: platform, id: platform, value: platform, selected: platform === value, onClick: (e) => e.preventDefault() }, label)));
    const onSelect = (_event, value) => {
        setValue(value);
        setIsOpen(false);
        if (value === 'external' || values.controlPlaneCount === 1) {
            setFieldValue('userManagedNetworking', true);
        }
        else {
            setFieldValue('userManagedNetworking', false);
        }
    };
    return isDisabled ? (React.createElement(ui_1.StaticField, { name: 'platform', label: t('ai:Integrate with external partner platforms'), isRequired: true }, platforms[value])) : (React.createElement(react_core_1.FormGroup, { isInline: true, label: t('ai:Integrate with external partner platforms'), isRequired: true, name: 'platform' },
        React.createElement(react_core_1.Dropdown, { isOpen: isOpen, toggle: (toggleRef) => (React.createElement(react_core_1.MenuToggle, { ref: toggleRef, className: "pf-v5-u-w-100", onClick: () => setIsOpen(!isOpen) }, value ? platforms[value] : t('ai:Integrate with external partner platforms'))), onSelect: onSelect }, options)));
};
exports.ExternalPlatformsDropdown = ExternalPlatformsDropdown;
//# sourceMappingURL=ExternalPlatformsDropdown.js.map