/*---------------------------------------------------------------------------------------------
 * 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
 */
import "./SectionTarget.scss";
import classnames from "classnames";
import * as React from "react";
import { assert } from "@itwin/core-bentley";
import { DraggedWidgetIdContext, useTarget } from "../base/DragManager";
import { CursorTypeContext, getUniqueId } from "../base/NineZone";
import { getCursorClassName } from "../widget-panels/CursorOverlay";
import { isHorizontalPanelSide, PanelSideContext, } from "../widget-panels/Panel";
import { useAllowedPanelTarget } from "./useAllowedPanelTarget";
import { useLayout } from "../base/LayoutStore";
/** @internal */
export function SectionTarget(props) {
    const { sectionIndex } = props;
    const cursorType = React.useContext(CursorTypeContext);
    const draggedTab = useLayout((state) => !!state.draggedTab);
    const draggedWidgetId = React.useContext(DraggedWidgetIdContext);
    const direction = useTargetDirection();
    const [ref, targeted] = useTarget(useSectionTargetArgs(sectionIndex));
    const allowedTarget = useAllowedPanelTarget();
    const hidden = !allowedTarget || (!draggedTab && !draggedWidgetId);
    const className = classnames("nz-target-sectionTarget", `nz-${direction}`, targeted && "nz-targeted", hidden && "nz-hidden", cursorType && getCursorClassName(cursorType));
    return (React.createElement("div", { className: className, ref: ref },
        React.createElement("div", { className: classnames("nz-section", "nz-start", sectionIndex === 0 && "nz-target") }),
        React.createElement("div", { className: "nz-border" }),
        React.createElement("div", { className: classnames("nz-section", "nz-end", sectionIndex === 1 && "nz-target") })));
}
/** @internal */
export function useSectionTargetArgs(sectionIndex) {
    const side = React.useContext(PanelSideContext);
    const newWidgetId = React.useMemo(() => getUniqueId(), []);
    return React.useMemo(() => {
        assert(!!side);
        return {
            type: "section",
            side,
            sectionIndex,
            newWidgetId,
        };
    }, [side, sectionIndex, newWidgetId]);
}
/** @internal */
export function useTargetDirection() {
    const side = React.useContext(PanelSideContext);
    assert(!!side);
    if (isHorizontalPanelSide(side)) {
        return "horizontal";
    }
    return "vertical";
}
//# sourceMappingURL=SectionTarget.js.map