"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.NetworkTypeDropDown = void 0;
const tslib_1 = require("tslib");
const react_1 = tslib_1.__importDefault(require("react"));
const formik_1 = require("formik");
const react_core_1 = require("@patternfly/react-core");
const ui_1 = require("../../../../common/components/ui");
const networkType_1 = require("../../../../common/types/networkType");
const hooks_1 = require("../../../../common/hooks");
const common_1 = require("../../../../common");
const NetworkTypeDropDown = ({ isSDNSelectable }) => {
    const { t } = (0, hooks_1.useTranslation)();
    const [field, , { setValue }] = (0, formik_1.useField)('networkType');
    const [isOpen, setOpen] = react_1.default.useState(false);
    const { values } = (0, formik_1.useFormikContext)();
    const fieldId = (0, ui_1.getFieldId)('networkType', 'input');
    const showThirdPartyBanner = (0, networkType_1.isThirdPartyCNI)(values.networkType);
    const currentDisplayValue = (0, networkType_1.NETWORK_TYPE_LABELS)(t)[field.value];
    const dropdownItems = Object.entries((0, networkType_1.NETWORK_TYPE_LABELS)(t)).map(([value, label]) => (react_1.default.createElement(react_core_1.DropdownItem, { key: value, id: value, value: value, isAriaDisabled: value === networkType_1.NETWORK_TYPE_SDN && !isSDNSelectable }, label)));
    const onSelect = (_event, nextValue) => {
        if (nextValue) {
            setValue(nextValue);
        }
        setOpen(false);
    };
    const toggle = (toggleRef) => (react_1.default.createElement(react_core_1.MenuToggle, { ref: toggleRef, onClick: () => setOpen(!isOpen), isExpanded: isOpen, id: fieldId, className: "pf-v6-u-w-100", style: { minWidth: '100%' } }, currentDisplayValue || t('ai:Network type')));
    return (react_1.default.createElement(react_core_1.Stack, { hasGutter: true },
        react_1.default.createElement(react_core_1.StackItem, null,
            react_1.default.createElement(react_core_1.FormGroup, { fieldId: fieldId, label: t('ai:Network type'), id: `form-control__${fieldId}` },
                react_1.default.createElement(react_core_1.Dropdown, { id: `${fieldId}-dropdown`, onOpenChange: (open) => setOpen(open), onSelect: onSelect, toggle: toggle, isOpen: isOpen }, dropdownItems))),
        showThirdPartyBanner && react_1.default.createElement(common_1.ThirdPartyCNIBanner, null)));
};
exports.NetworkTypeDropDown = NetworkTypeDropDown;
//# sourceMappingURL=NetworkTypeDropdown.js.map