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;
};
import { jsx as _jsx } from "react/jsx-runtime";
import { useState } from 'react';
import { Tooltip, Dropdown, MenuToggle } from '@patternfly/react-core';
export 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] = useState(false);
    const [defaultAriaLabel, setDefaultAriaLabel] = useState('Select model');
    const toggle = (toggleRef) => (_jsx(Tooltip, Object.assign({ className: "pf-chatbot__tooltip", content: tooltipContent, position: "bottom", 
        // prevents VO announcements of both aria label and tooltip
        aria: "none" }, tooltipProps, { children: _jsx(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 (_jsx(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 })));
};
export default ChatbotHeaderSelectorDropdown;
