"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.MergeTarget = void 0;
require("./MergeTarget.scss");
const classnames_1 = require("classnames");
const React = require("react");
const DragManager_1 = require("../base/DragManager");
const NineZone_1 = require("../base/NineZone");
const CursorOverlay_1 = require("../widget-panels/CursorOverlay");
const useAllowedWidgetTarget_1 = require("./useAllowedWidgetTarget");
const LayoutStore_1 = require("../base/LayoutStore");
/** @internal */
function MergeTarget(props) {
    const { widgetId } = props;
    const cursorType = React.useContext(NineZone_1.CursorTypeContext);
    const draggedWidgetId = React.useContext(DragManager_1.DraggedWidgetIdContext);
    const draggedTab = (0, LayoutStore_1.useLayout)((state) => !!state.draggedTab);
    const [ref, targeted] = (0, DragManager_1.useTarget)(useTargetArgs(widgetId));
    const allowedTarget = (0, useAllowedWidgetTarget_1.useAllowedWidgetTarget)(widgetId);
    const hidden = !allowedTarget ||
        (!draggedTab && !draggedWidgetId) ||
        draggedWidgetId === widgetId;
    const className = (0, classnames_1.default)("nz-target-mergeTarget", targeted && "nz-targeted", hidden && "nz-hidden", cursorType && (0, CursorOverlay_1.getCursorClassName)(cursorType));
    return React.createElement("div", { className: className, ref: ref });
}
exports.MergeTarget = MergeTarget;
function useTargetArgs(widgetId) {
    return React.useMemo(() => {
        return {
            type: "widget",
            widgetId,
        };
    }, [widgetId]);
}
//# sourceMappingURL=MergeTarget.js.map