"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SimpleDropdown = void 0;
const tslib_1 = require("tslib");
const react_1 = tslib_1.__importDefault(require("react"));
const react_core_1 = require("@patternfly/react-core");
require("./SimpleDropdown.css");
const SimpleDropdown = ({ current, defaultValue, items, setValue, isDisabled, idPrefix, menuAppendTo, }) => {
    const [isOpen, setOpen] = react_1.default.useState(false);
    const dropdownItems = items.map(({ value, label, description }) => (react_1.default.createElement(react_core_1.DropdownItem, { key: value, id: value, description: description }, label)));
    const onSelect = react_1.default.useCallback((event) => {
        setValue(event === null || event === void 0 ? void 0 : event.currentTarget.id);
        setOpen(false);
    }, [setValue, setOpen]);
    const toggle = (toggleRef) => (react_1.default.createElement(react_core_1.MenuToggle, { id: idPrefix ? `${idPrefix}-dropdown-toggle-items` : undefined, className: "role-dropdown", ref: toggleRef, variant: "plainText", onClick: () => setOpen(!isOpen), isDisabled: isDisabled, isExpanded: isOpen, "data-testid": "simple-dropdown-toggle" }, current || defaultValue));
    return (react_1.default.createElement(react_core_1.Dropdown, { onSelect: onSelect, onOpenChange: () => setOpen(!isOpen), toggle: toggle, isOpen: isOpen, id: idPrefix ? `${idPrefix}-dropdown-toggle` : undefined, popperProps: { appendTo: menuAppendTo } }, dropdownItems));
};
exports.SimpleDropdown = SimpleDropdown;
//# sourceMappingURL=SimpleDropdown.js.map