/*---------------------------------------------------------------------------------------------
 * 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, MenuExtraContent } from "@itwin/itwinui-react";
import { ExpandIndicator } from "./ExpandIndicator.js";
import { Item } from "./Item.js";
import { GroupMenuItem, usePopoverPlacement } from "./GroupItem.js";
import { ToolGroupOverflowContext } from "./OverflowButton.js";
import { ToolbarContext } from "./Toolbar.js";
import { useSafeContext } from "../../hooks/useSafeContext.js";
/** @internal */
export const CustomItem = React.forwardRef(function CustomItem({ item }, ref) {
    const placement = usePopoverPlacement();
    const { setPopoverOpen } = useSafeContext(ToolbarContext);
    const overflowContext = React.useContext(ToolGroupOverflowContext);
    if (overflowContext) {
        return React.createElement(GroupMenuItem, { item: item, onClose: overflowContext.onClose });
    }
    return (React.createElement(DropdownMenu, { menuItems: () => {
            return [
                React.createElement(MenuExtraContent, { key: 0 }, item.panelContent),
            ];
        }, placement: placement, onVisibleChange: (newVisible) => {
            setPopoverOpen(newVisible);
        } },
        React.createElement(Item, { ref: ref, item: item },
            React.createElement(ExpandIndicator, null))));
});
//# sourceMappingURL=CustomItem.js.map