"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 Widget
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.WidgetMenuTab = void 0;
require("./MenuTab.scss");
const classnames_1 = require("classnames");
const React = require("react");
const core_bentley_1 = require("@itwin/core-bentley");
const core_react_1 = require("@itwin/core-react");
const Tab_1 = require("./Tab");
const Widget_1 = require("./Widget");
const Overflow_1 = require("./Overflow");
const NineZone_1 = require("../base/NineZone");
const LayoutStore_1 = require("../base/LayoutStore");
const ContentRenderer_1 = require("./ContentRenderer");
/** @internal */
function WidgetMenuTab(props) {
    const id = React.useContext(ContentRenderer_1.TabIdContext);
    const overflowContext = React.useContext(Overflow_1.WidgetOverflowContext);
    const showWidgetIcon = React.useContext(NineZone_1.ShowWidgetIconContext);
    (0, core_bentley_1.assert)(!!id);
    const { label, iconSpec } = (0, LayoutStore_1.useLayout)((state) => {
        const tab = state.tabs[id];
        return {
            label: tab.label,
            iconSpec: tab.iconSpec,
        };
    }, true);
    (0, core_bentley_1.assert)(!!overflowContext);
    const closeOverflow = React.useCallback(() => {
        overflowContext.close();
    }, [overflowContext]);
    const ref = (0, Tab_1.useTabInteractions)({
        onDragStart: closeOverflow,
        onClick: closeOverflow,
        onDoubleClick: closeOverflow,
    });
    const activeTabId = (0, Widget_1.useActiveTabId)();
    const active = activeTabId === id;
    const className = (0, classnames_1.default)("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" }, iconSpec && React.createElement(core_react_1.Icon, { iconSpec: iconSpec }))),
        React.createElement("span", null, label),
        React.createElement("div", { className: (0, classnames_1.default)("nz-checkmark", !active && "nz-hidden") })));
}
exports.WidgetMenuTab = WidgetMenuTab;
//# sourceMappingURL=MenuTab.js.map