'use client';
import * as React from 'react';
import { Menu, MenuTrigger, MenuPopover, MenuList, MenuItem } from '@fluentui/react-menu';
import { MenuButton } from '@fluentui/react-button';
import { useOverflowMenu } from '@fluentui/react-overflow';
export const OverflowMenu = ({ itemIds, title, items })=>{
    const { ref, overflowCount, isOverflowing } = useOverflowMenu();
    let displayLabel = title;
    displayLabel = title === '' ? `+${overflowCount} items` : `+${overflowCount} ${title}`;
    if (!isOverflowing) {
        return null;
    }
    const remainingItemsCount = itemIds.length - overflowCount;
    const menuList = [];
    for(let i = remainingItemsCount; i < itemIds.length; i++){
        const buttonElement = items[i];
        menuList.push(/*#__PURE__*/ React.createElement(MenuItem, {
            tabIndex: -1,
            key: i,
            onClick: (e)=>{
                const button = buttonElement.props;
                if (button.onClick) {
                    button.onClick(e);
                }
            }
        }, buttonElement));
    }
    return /*#__PURE__*/ React.createElement(Menu, null, /*#__PURE__*/ React.createElement(MenuTrigger, {
        disableButtonEnhancement: true
    }, /*#__PURE__*/ React.createElement(MenuButton, {
        ref: ref
    }, displayLabel)), /*#__PURE__*/ React.createElement(MenuPopover, null, /*#__PURE__*/ React.createElement(MenuList, null, menuList)));
};
