/*---------------------------------------------------------------------------------------------
 * 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 { IconButton } from "@itwin/itwinui-react";
import { SvgMore } from "@itwin/itwinui-icons-react";
import { useLabelProps } from "./Item.js";
import { ToolbarMenu, usePopoverPlacement } from "./GroupItem.js";
import { ToolbarContext } from "./Toolbar.js";
import { useSafeContext } from "../../hooks/useSafeContext.js";
/** @internal */
export const ToolGroupOverflowContext = React.createContext(undefined);
/** @internal */
export const OverflowButton = React.forwardRef(function OverflowButton(props, ref) {
    const placement = usePopoverPlacement();
    const labelProps = useLabelProps();
    const { setPopoverOpen } = useSafeContext(ToolbarContext);
    return (React.createElement(ToolbarMenu, { menuItems: (close) => {
            return [
                React.createElement(OverflowMenu, { key: 0, onClose: close }, props.children),
            ];
        }, placement: placement, onVisibleChange: (newVisible) => {
            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