"use strict";
var __rest = (this && this.__rest) || function (s, e) {
    var t = {};
    for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
        t[p] = s[p];
    if (s != null && typeof Object.getOwnPropertySymbols === "function")
        for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
            if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
                t[p[i]] = s[p[i]];
        }
    return t;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ChatbotHeaderSelectorDropdown = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = require("react");
const react_core_1 = require("@patternfly/react-core");
const ChatbotHeaderSelectorDropdown = (_a) => {
    var { value, className, children, onSelect, tooltipProps, tooltipContent = 'Select model', menuToggleAriaLabel, isCompact, toggleProps, dropdownWidth } = _a, props = __rest(_a, ["value", "className", "children", "onSelect", "tooltipProps", "tooltipContent", "menuToggleAriaLabel", "isCompact", "toggleProps", "dropdownWidth"]);
    const [isOptionsMenuOpen, setIsOptionsMenuOpen] = (0, react_1.useState)(false);
    const [defaultAriaLabel, setDefaultAriaLabel] = (0, react_1.useState)('Select model');
    const toggle = (toggleRef) => ((0, jsx_runtime_1.jsx)(react_core_1.Tooltip, Object.assign({ className: "pf-chatbot__tooltip", content: tooltipContent, position: "bottom", 
        // prevents VO announcements of both aria label and tooltip
        aria: "none" }, tooltipProps, { children: (0, jsx_runtime_1.jsx)(react_core_1.MenuToggle, Object.assign({ variant: "secondary", "aria-label": menuToggleAriaLabel !== null && menuToggleAriaLabel !== void 0 ? menuToggleAriaLabel : defaultAriaLabel, ref: toggleRef, isExpanded: isOptionsMenuOpen, onClick: () => setIsOptionsMenuOpen(!isOptionsMenuOpen), size: isCompact ? 'sm' : undefined, className: `${isCompact ? 'pf-m-compact' : ''}` }, toggleProps, { style: {
                width: dropdownWidth
            }, children: value })) })));
    return ((0, jsx_runtime_1.jsx)(react_core_1.Dropdown, Object.assign({ className: `pf-chatbot__selections ${className !== null && className !== void 0 ? className : ''}`, isOpen: isOptionsMenuOpen, onSelect: (e, value) => {
            onSelect && onSelect(e, value);
            setDefaultAriaLabel(`Select model: ${value}`);
            setIsOptionsMenuOpen(false);
        }, onOpenChange: (isOpen) => setIsOptionsMenuOpen(isOpen), popperProps: { position: 'right', appendTo: 'inline' }, shouldFocusToggleOnSelect: true, shouldFocusFirstItemOnOpen: true, toggle: toggle }, props, { children: children })));
};
exports.ChatbotHeaderSelectorDropdown = ChatbotHeaderSelectorDropdown;
exports.default = exports.ChatbotHeaderSelectorDropdown;
