"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.PanelTargets = void 0;
require("./PanelTargets.scss");
const classnames_1 = require("classnames");
const React = require("react");
const core_bentley_1 = require("@itwin/core-bentley");
const TargetContainer_1 = require("./TargetContainer");
const PanelTarget_1 = require("./PanelTarget");
const SectionTarget_1 = require("./SectionTarget");
const MergeTarget_1 = require("./MergeTarget");
const PanelState_1 = require("../state/PanelState");
const Panel_1 = require("../widget-panels/Panel");
const LayoutStore_1 = require("../base/LayoutStore");
/** @internal */
function PanelTargets() {
    const side = React.useContext(Panel_1.PanelSideContext);
    (0, core_bentley_1.assert)(!!side);
    const widgets = (0, LayoutStore_1.useLayout)((state) => state.panels[side].widgets, true);
    const span = (0, LayoutStore_1.useLayout)((state) => {
        const panel = state.panels[side];
        return (0, PanelState_1.isHorizontalPanelState)(panel) && panel.span;
    });
    const direction = (0, SectionTarget_1.useTargetDirection)();
    const type = usePanelTargetsType();
    const className = (0, classnames_1.default)("nz-target-panelTargets", `nz-${side}`, type === "two-widgets" && "nz-wide", span && "nz-span");
    let targets;
    if (type === "no-panel") {
        targets = React.createElement(PanelTarget_1.PanelTarget, { side: side });
    }
    else if (type === "single-widget") {
        targets = (React.createElement(React.Fragment, null,
            React.createElement(SectionTarget_1.SectionTarget, { sectionIndex: 0 }),
            React.createElement(MergeTarget_1.MergeTarget, { widgetId: widgets[0] }),
            React.createElement(SectionTarget_1.SectionTarget, { sectionIndex: 1 })));
    }
    else if (type === "two-widgets") {
        targets = (React.createElement(React.Fragment, null,
            React.createElement(MergeTarget_1.MergeTarget, { widgetId: widgets[0] }),
            React.createElement(MergeTarget_1.MergeTarget, { widgetId: widgets[1] })));
    }
    return (React.createElement(TargetContainer_1.TargetContainer, { className: className, direction: direction }, targets));
}
exports.PanelTargets = PanelTargets;
function usePanelTargetsType() {
    const side = React.useContext(Panel_1.PanelSideContext);
    (0, core_bentley_1.assert)(!!side);
    return (0, LayoutStore_1.useLayout)((state) => {
        const panel = state.panels[side];
        if (panel.widgets.length === 0)
            return "no-panel";
        if (!panel.collapsed)
            return "hidden";
        if (panel.widgets.length === 2)
            return "two-widgets";
        (0, core_bentley_1.assert)(panel.widgets.length === 1);
        return "single-widget";
    });
}
//# sourceMappingURL=PanelTargets.js.map