"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DiscoveryImageTypeDropdown = exports.discoveryImageTypes = void 0;
const tslib_1 = require("tslib");
const react_1 = tslib_1.__importDefault(require("react"));
const react_core_1 = require("@patternfly/react-core");
const react_core_2 = require("@patternfly/react-core");
const formik_1 = require("formik");
const common_1 = require("../../../common");
exports.discoveryImageTypes = {
    'minimal-iso': 'Minimal image file - Download an ISO that fetches content on boot',
    'full-iso': 'Full image file - Download a self-contained ISO',
    'discovery-image-ipxe': 'iPXE - Provision from your network server',
};
const DiscoveryImageTypeDropdown = ({ name, defaultValue, onChange, selectedCpuArchitecture, isDisabled = false, }) => {
    const [field, { value }, { setValue }] = (0, formik_1.useField)(name);
    const [isOpen, setOpen] = react_1.default.useState(false);
    const [current, setCurrent] = react_1.default.useState(defaultValue);
    const fieldId = (0, common_1.getFieldId)(name, 'input');
    const isMinimalISODisabled = selectedCpuArchitecture && selectedCpuArchitecture === common_1.CpuArchitecture.s390x;
    const dropdownItems = [
        react_1.default.createElement(react_core_2.DropdownItem, { key: "full-iso", id: "full-iso", description: 'Use when configuring custom networking for easier debugging', value: exports.discoveryImageTypes['full-iso'] }, exports.discoveryImageTypes['full-iso']),
        react_1.default.createElement(react_core_2.Divider, { component: "li", key: "separator1" }),
        react_1.default.createElement(react_core_1.Tooltip, { key: "minimal-iso-tooltip", content: isMinimalISODisabled ? (react_1.default.createElement("p", null, 'This provisioning type is not supported when using s390x architecture')) : undefined },
            react_1.default.createElement(react_core_2.DropdownItem, { key: "minimal-iso", id: "minimal-iso", description: 'Use when provisioning with default networking options', isAriaDisabled: !!isMinimalISODisabled, value: exports.discoveryImageTypes['minimal-iso'] }, exports.discoveryImageTypes['minimal-iso'])),
        react_1.default.createElement(react_core_2.Divider, { component: "li", key: "separator2" }),
        react_1.default.createElement(react_core_2.DropdownItem, { key: "discovery-image-ipxe", id: "discovery-image-ipxe", description: 'Use when your platform does not support booting from ISO', value: exports.discoveryImageTypes['discovery-image-ipxe'] }, exports.discoveryImageTypes['discovery-image-ipxe']),
    ];
    const onSelect = (event, value) => {
        const imageTypeSelection = value;
        setCurrent(imageTypeSelection ? imageTypeSelection : '');
        setValue(event === null || event === void 0 ? void 0 : event.currentTarget.id);
        setOpen(false);
        onChange(imageTypeSelection === 'discovery-image-ipxe');
    };
    const toggle = (toggleRef) => (react_1.default.createElement(react_core_2.MenuToggle, { id: fieldId, className: "pf-v6-u-w-100", ref: toggleRef, isFullWidth: true, onClick: () => setOpen(!isOpen), isExpanded: isOpen, isDisabled: isDisabled, style: { minWidth: '510px' }, "data-testid": "discovery-image-type-dropdown-toggle" }, current || value));
    return (react_1.default.createElement(react_core_1.FormGroup, { fieldId: fieldId, label: 'Provisioning type' },
        react_1.default.createElement(react_core_2.Dropdown, Object.assign({}, field, { id: `${fieldId}-dropdown`, toggle: toggle, isOpen: isOpen, onSelect: onSelect, onOpenChange: () => setOpen(!isOpen) }),
            react_1.default.createElement(react_core_2.DropdownList, null, dropdownItems))));
};
exports.DiscoveryImageTypeDropdown = DiscoveryImageTypeDropdown;
exports.default = exports.DiscoveryImageTypeDropdown;
//# sourceMappingURL=DiscoveryImageTypeDropdown.js.map