"use strict";
/*---------------------------------------------------------------------------------------------
 * 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
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.CustomItem = void 0;
const React = require("react");
const itwinui_react_1 = require("@itwin/itwinui-react");
const ExpandIndicator_1 = require("./ExpandIndicator");
const Item_1 = require("./Item");
const GroupItem_1 = require("./GroupItem");
const OverflowButton_1 = require("./OverflowButton");
const Toolbar_1 = require("./Toolbar");
/** @internal */
exports.CustomItem = React.forwardRef(function CustomItem({ item }, ref) {
    const placement = (0, GroupItem_1.usePopoverPlacement)();
    const context = React.useContext(Toolbar_1.ToolbarContext);
    const overflowContext = React.useContext(OverflowButton_1.ToolGroupOverflowContext);
    if (overflowContext) {
        return React.createElement(GroupItem_1.GroupMenuItem, { item: item, onClose: overflowContext.onClose });
    }
    return (React.createElement(itwinui_react_1.DropdownMenu, { menuItems: () => {
            return [
                React.createElement(itwinui_react_1.MenuExtraContent, { key: 0 }, item.panelContent),
            ];
        }, placement: placement, onVisibleChange: (newVisible) => {
            context?.setPopoverOpen(newVisible);
        } },
        React.createElement(Item_1.Item, { ref: ref, item: item },
            React.createElement(ExpandIndicator_1.ExpandIndicator, null))));
});
//# sourceMappingURL=CustomItem.js.map