/*---------------------------------------------------------------------------------------------
 * 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 classnames from "classnames";
import * as React from "react";
import { assert } from "@itwin/core-bentley";
import { useTabInteractions } from "./Tab";
import { useActiveTabId } from "./Widget";
import { WidgetOverflowContext } from "./Overflow";
import { ShowWidgetIconContext } from "../base/NineZone";
import { useLayout } from "../base/LayoutStore";
import { TabIdContext } from "./ContentRenderer";
/** @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;
    const className = classnames("nz-widget-menuTab", !showWidgetIcon && "nz-no-icon", props.className);
    return (React.createElement("div", { className: className, ref: ref, title: label },
        props.badge && React.createElement("div", { className: "nz-badge" }, props.badge),
        showWidgetIcon && React.createElement("div", { className: "nz-icon" }, props.icon),
        React.createElement("span", null, label),
        React.createElement("div", { className: classnames("nz-checkmark", !active && "nz-hidden") })));
}
//# sourceMappingURL=MenuTab.js.map