/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
 * @module Zone
 */
import * as React from "react";
import { Zone as NZ_Zone, } from "@itwin/appui-layout-react";
import { SafeAreaContext } from "../safearea/SafeAreaContext";
import { WidgetStack } from "../widgets/WidgetStack";
import { Outline } from "./Outline";
import { ZoneTargets } from "../dragdrop/ZoneTargets";
/** FrameworkZone React component.
 * @internal
 */
export class FrameworkZone extends React.PureComponent {
    render() {
        const zIndexStyle = getFloatingZoneStyle(this.props.zone);
        const floatingBounds = getFloatingZoneBounds(this.props.zone);
        return (React.createElement(SafeAreaContext.Consumer, null, (safeAreaInsets) => (React.createElement("span", { style: zIndexStyle },
            React.createElement(NZ_Zone, { bounds: floatingBounds, className: this.props.className, style: this.props.style, isFloating: !!this.props.zone.floating, isHidden: this.props.isHidden, isInFooterMode: this.props.isInFooterMode, id: this.props.zone.id, safeAreaInsets: safeAreaInsets }, this._getWidget()),
            React.createElement(NZ_Zone, { bounds: this.props.zone.bounds, id: this.props.zone.id, isInFooterMode: this.props.isInFooterMode, safeAreaInsets: safeAreaInsets },
                React.createElement(ZoneTargets, { zoneId: this.props.zone.id, dropTarget: this.props.dropTarget, targetChangeHandler: this.props.targetChangeHandler })),
            React.createElement(Outline, { bounds: this.props.targetedBounds })))));
    }
    _getWidget() {
        const widget = this.props.widget;
        if (!widget)
            return null;
        if (this.props.widgetElement !== undefined)
            return this.props.widgetElement;
        return (React.createElement(WidgetStack, { activeTabIndex: this.props.activeTabIndex, disabledResizeHandles: this.props.disabledResizeHandles, draggedWidget: this.props.draggedWidget, fillZone: this.props.fillZone || this.props.zone.isLayoutChanged, getWidgetContentRef: this.props.getWidgetContentRef, horizontalAnchor: widget.horizontalAnchor, isCollapsed: false, isFloating: !!this.props.zone.floating, isInStagePanel: false, openWidgetId: this.props.openWidgetId, verticalAnchor: widget.verticalAnchor, widgets: this.props.zone.widgets, widgetTabs: this.props.widgetTabs, widgetChangeHandler: this.props.widgetChangeHandler }));
    }
}
/** @internal */
export const getFloatingZoneBounds = (props) => {
    return props.floating ? props.floating.bounds : props.bounds;
};
/** @internal */
export const getFloatingZoneStyle = (props) => {
    return props.floating ? {
        zIndex: props.floating.stackId,
        position: "relative",
    } : undefined;
};
//# sourceMappingURL=FrameworkZone.js.map