"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 Zone
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.getFloatingZoneStyle = exports.getFloatingZoneBounds = exports.FrameworkZone = void 0;
const React = require("react");
const appui_layout_react_1 = require("@itwin/appui-layout-react");
const SafeAreaContext_1 = require("../safearea/SafeAreaContext");
const WidgetStack_1 = require("../widgets/WidgetStack");
const Outline_1 = require("./Outline");
const ZoneTargets_1 = require("../dragdrop/ZoneTargets");
/** FrameworkZone React component.
 * @internal
 */
class FrameworkZone extends React.PureComponent {
    render() {
        const zIndexStyle = (0, exports.getFloatingZoneStyle)(this.props.zone);
        const floatingBounds = (0, exports.getFloatingZoneBounds)(this.props.zone);
        return (React.createElement(SafeAreaContext_1.SafeAreaContext.Consumer, null, (safeAreaInsets) => (React.createElement("span", { style: zIndexStyle },
            React.createElement(appui_layout_react_1.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(appui_layout_react_1.Zone, { bounds: this.props.zone.bounds, id: this.props.zone.id, isInFooterMode: this.props.isInFooterMode, safeAreaInsets: safeAreaInsets },
                React.createElement(ZoneTargets_1.ZoneTargets, { zoneId: this.props.zone.id, dropTarget: this.props.dropTarget, targetChangeHandler: this.props.targetChangeHandler })),
            React.createElement(Outline_1.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_1.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 }));
    }
}
exports.FrameworkZone = FrameworkZone;
/** @internal */
const getFloatingZoneBounds = (props) => {
    return props.floating ? props.floating.bounds : props.bounds;
};
exports.getFloatingZoneBounds = getFloatingZoneBounds;
/** @internal */
const getFloatingZoneStyle = (props) => {
    return props.floating ? {
        zIndex: props.floating.stackId,
        position: "relative",
    } : undefined;
};
exports.getFloatingZoneStyle = getFloatingZoneStyle;
//# sourceMappingURL=FrameworkZone.js.map