/*---------------------------------------------------------------------------------------------
 * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
 * See LICENSE.md in the project root for license terms and full copyright notice.
 *--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
 * @module Toolbar
 */
import * as React from "react";
import { DropdownMenu, IconButton } from "@itwin/itwinui-react";
import { SvgMore } from "@itwin/itwinui-icons-react";
import { useLabelProps } from "./Item";
import { usePopoverPlacement } from "./GroupItem";
import { ToolbarContext } from "./Toolbar";
/** @internal */
export const ToolGroupOverflowContext = React.createContext(undefined);
/** @internal */
export const OverflowButton = React.forwardRef(function OverflowButton(props, ref) {
    const placement = usePopoverPlacement();
    const labelProps = useLabelProps();
    const context = React.useContext(ToolbarContext);
    return (React.createElement(DropdownMenu, { menuItems: (close) => {
            return [
                React.createElement(OverflowMenu, { key: 0, onClose: close }, props.children),
            ];
        }, placement: placement, onVisibleChange: (newVisible) => {
            context?.setPopoverOpen(newVisible);
        } },
        React.createElement(IconButton, { ref: ref, label: "More", labelProps: labelProps, styleType: "borderless" },
            React.createElement(SvgMore, null))));
});
function OverflowMenu({ children, onClose }) {
    return (React.createElement(ToolGroupOverflowContext.Provider, { value: { onClose } }, children));
}
//# sourceMappingURL=OverflowButton.js.map