"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.TitleBarTarget = void 0;
require("./TitleBarTarget.scss");
const classnames_1 = require("classnames");
const React = require("react");
const core_bentley_1 = require("@itwin/core-bentley");
const DragManager_1 = require("../base/DragManager");
const NineZone_1 = require("../base/NineZone");
const CursorOverlay_1 = require("../widget-panels/CursorOverlay");
const Widget_1 = require("../widget/Widget");
const TabOutline_1 = require("../outline/TabOutline");
const useAllowedWidgetTarget_1 = require("./useAllowedWidgetTarget");
const LayoutStore_1 = require("../base/LayoutStore");
const SendBack_1 = require("../widget/SendBack");
/** @internal */
function TitleBarTarget() {
    const cursorType = React.useContext(NineZone_1.CursorTypeContext);
    const draggedWidgetId = React.useContext(DragManager_1.DraggedWidgetIdContext);
    const widgetId = React.useContext(Widget_1.WidgetIdContext);
    const activeHomeState = (0, SendBack_1.useSendBackHomeState)();
    (0, core_bentley_1.assert)(!!widgetId);
    const draggedTab = (0, LayoutStore_1.useLayout)((state) => !!state.draggedTab);
    const [ref] = (0, DragManager_1.useTarget)(useTargetArgs(widgetId));
    const allowedTarget = (0, useAllowedWidgetTarget_1.useAllowedWidgetTarget)(widgetId);
    const hidden = !allowedTarget ||
        (((!draggedTab && !draggedWidgetId) || draggedWidgetId === widgetId) &&
            !(activeHomeState?.widgetId === widgetId));
    const className = (0, classnames_1.default)("nz-target-titleBarTarget", hidden && "nz-hidden", cursorType && (0, CursorOverlay_1.getCursorClassName)(cursorType));
    return (React.createElement("div", { className: className, ref: ref },
        React.createElement(TabOutline_1.TabOutline, null)));
}
exports.TitleBarTarget = TitleBarTarget;
function useTargetArgs(widgetId) {
    return React.useMemo(() => {
        return {
            type: "widget",
            widgetId,
        };
    }, [widgetId]);
}
//# sourceMappingURL=TitleBarTarget.js.map