"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 WidgetPanels
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.useTargetDirection = exports.useSectionTargetArgs = exports.SectionTarget = void 0;
require("./SectionTarget.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 Panel_1 = require("../widget-panels/Panel");
const useAllowedPanelTarget_1 = require("./useAllowedPanelTarget");
const LayoutStore_1 = require("../base/LayoutStore");
/** @internal */
function SectionTarget(props) {
    const { sectionIndex } = props;
    const cursorType = React.useContext(NineZone_1.CursorTypeContext);
    const draggedTab = (0, LayoutStore_1.useLayout)((state) => !!state.draggedTab);
    const draggedWidgetId = React.useContext(DragManager_1.DraggedWidgetIdContext);
    const direction = useTargetDirection();
    const [ref, targeted] = (0, DragManager_1.useTarget)(useSectionTargetArgs(sectionIndex));
    const allowedTarget = (0, useAllowedPanelTarget_1.useAllowedPanelTarget)();
    const hidden = !allowedTarget || (!draggedTab && !draggedWidgetId);
    const className = (0, classnames_1.default)("nz-target-sectionTarget", `nz-${direction}`, targeted && "nz-targeted", hidden && "nz-hidden", cursorType && (0, CursorOverlay_1.getCursorClassName)(cursorType));
    return (React.createElement("div", { className: className, ref: ref },
        React.createElement("div", { className: (0, classnames_1.default)("nz-section", "nz-start", sectionIndex === 0 && "nz-target") }),
        React.createElement("div", { className: "nz-border" }),
        React.createElement("div", { className: (0, classnames_1.default)("nz-section", "nz-end", sectionIndex === 1 && "nz-target") })));
}
exports.SectionTarget = SectionTarget;
/** @internal */
function useSectionTargetArgs(sectionIndex) {
    const side = React.useContext(Panel_1.PanelSideContext);
    const newWidgetId = React.useMemo(() => (0, NineZone_1.getUniqueId)(), []);
    return React.useMemo(() => {
        (0, core_bentley_1.assert)(!!side);
        return {
            type: "section",
            side,
            sectionIndex,
            newWidgetId,
        };
    }, [side, sectionIndex, newWidgetId]);
}
exports.useSectionTargetArgs = useSectionTargetArgs;
/** @internal */
function useTargetDirection() {
    const side = React.useContext(Panel_1.PanelSideContext);
    (0, core_bentley_1.assert)(!!side);
    if ((0, Panel_1.isHorizontalPanelSide)(side)) {
        return "horizontal";
    }
    return "vertical";
}
exports.useTargetDirection = useTargetDirection;
//# sourceMappingURL=SectionTarget.js.map