/*---------------------------------------------------------------------------------------------
 * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
 * See LICENSE.md in the project root for license terms and full copyright notice.
 *--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
 * @module Widget
 */
import "./MenuTab.scss";
import * as React from "react";
import { assert } from "@itwin/core-bentley";
import { SvgCheckmark } from "@itwin/itwinui-icons-react";
import { MenuItem } from "@itwin/itwinui-react";
import { useTabInteractions } from "./Tab.js";
import { useActiveTabId } from "./Widget.js";
import { WidgetOverflowContext } from "./Overflow.js";
import { ShowWidgetIconContext } from "../base/NineZone.js";
import { useLayout } from "../base/LayoutStore.js";
import { TabIdContext } from "./ContentRenderer.js";
/** @internal */
export function WidgetMenuTab(props) {
    const id = React.useContext(TabIdContext);
    const overflowContext = React.useContext(WidgetOverflowContext);
    const showWidgetIcon = React.useContext(ShowWidgetIconContext);
    assert(!!id);
    const label = useLayout((state) => {
        const tab = state.tabs[id];
        return tab.label;
    });
    assert(!!overflowContext);
    const closeOverflow = React.useCallback(() => {
        overflowContext.close();
    }, [overflowContext]);
    const ref = useTabInteractions({
        onDragStart: closeOverflow,
        onClick: closeOverflow,
        onDoubleClick: closeOverflow,
    });
    const activeTabId = useActiveTabId();
    const active = activeTabId === id;
    return (React.createElement(MenuItem, { role: "menuitemcheckbox", ref: ref, title: label, startIcon: showWidgetIcon ? props.icon : undefined, endIcon: active ? React.createElement(SvgCheckmark, null) : React.createElement(React.Fragment, null), "aria-checked": active, isSelected: active, "aria-selected": undefined },
        props.badge && (React.createElement("div", { className: "nz-widget-menuTab_badge" }, props.badge)),
        label));
}
//# sourceMappingURL=MenuTab.js.map