"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.useHidden = exports.PanelOutline = void 0;
require("./PanelOutline.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 Panel_1 = require("../widget-panels/Panel");
const PanelState_1 = require("../state/PanelState");
const DropTargetState_1 = require("../state/DropTargetState");
const LayoutStore_1 = require("../base/LayoutStore");
const SendBack_1 = require("../widget/SendBack");
/** @internal */
function PanelOutline() {
    const side = React.useContext(Panel_1.PanelSideContext);
    (0, core_bentley_1.assert)(!!side);
    const isHorizontal = (0, Panel_1.isHorizontalPanelSide)(side);
    const span = (0, LayoutStore_1.useLayout)((state) => {
        const panel = state.panels[side];
        return (0, PanelState_1.isHorizontalPanelState)(panel) ? panel.span : false;
    });
    const hidden = useHidden();
    const className = (0, classnames_1.default)("nz-outline-panelOutline", hidden && "nz-hidden", `nz-${side}`, span && "nz-span");
    const size = useSize();
    return (React.createElement("div", { className: className, style: {
            width: isHorizontal ? undefined : size,
            height: isHorizontal ? size : undefined,
        } }));
}
exports.PanelOutline = PanelOutline;
/** @internal */
function useHidden() {
    const side = React.useContext(Panel_1.PanelSideContext);
    const targeted = (0, DragManager_1.useTargeted)();
    const activeHomeState = (0, SendBack_1.useSendBackHomeState)();
    return React.useMemo(() => {
        if (activeHomeState) {
            if (activeHomeState.side === side &&
                activeHomeState.widgetId === undefined &&
                activeHomeState.sectionIndex === undefined)
                return false;
        }
        if (!targeted)
            return true;
        if (!(0, DropTargetState_1.isPanelDropTargetState)(targeted))
            return true;
        if (targeted.side !== side)
            return true;
        return false;
    }, [side, targeted, activeHomeState]);
}
exports.useHidden = useHidden;
function useSize() {
    const side = React.useContext(Panel_1.PanelSideContext);
    (0, core_bentley_1.assert)(!!side);
    return (0, LayoutStore_1.useLayout)((state) => {
        const panel = state.panels[side];
        return panel.size !== undefined ? panel.size : panel.minSize;
    });
}
//# sourceMappingURL=PanelOutline.js.map