/**
 * DevExtreme (esm/__internal/ui/popup/m_popup_position_controller.js)
 * Version: 23.2.9 (build 24294-0112)
 * Build date: Sun Oct 20 2024
 *
 * Copyright (c) 2012 - 2024 Developer Express Inc. ALL RIGHTS RESERVED
 * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
 */
import _extends from "@babel/runtime/helpers/esm/extends";
var __rest = this && this.__rest || function(s, e) {
    var t = {};
    for (var p in s) {
        if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) {
            t[p] = s[p]
        }
    }
    if (null != s && "function" === typeof Object.getOwnPropertySymbols) {
        var i = 0;
        for (p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
            if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) {
                t[p[i]] = s[p[i]]
            }
        }
    }
    return t
};
import {
    move
} from "../../../animation/translator";
import $ from "../../../core/renderer";
import {
    originalViewPort
} from "../../../core/utils/view_port";
import {
    getWindow
} from "../../../core/utils/window";
import {
    OverlayPositionController
} from "../../ui/overlay/m_overlay_position_controller";
var window = getWindow();
class PopupPositionController extends OverlayPositionController {
    constructor(_a) {
        var {
            fullScreen: fullScreen,
            forceApplyBindings: forceApplyBindings,
            dragOutsideBoundary: dragOutsideBoundary,
            dragAndResizeArea: dragAndResizeArea,
            outsideDragFactor: outsideDragFactor
        } = _a, args = __rest(_a, ["fullScreen", "forceApplyBindings", "dragOutsideBoundary", "dragAndResizeArea", "outsideDragFactor"]);
        super(args);
        this._props = _extends(_extends({}, this._props), {
            fullScreen: fullScreen,
            forceApplyBindings: forceApplyBindings,
            dragOutsideBoundary: dragOutsideBoundary,
            dragAndResizeArea: dragAndResizeArea,
            outsideDragFactor: outsideDragFactor
        });
        this._$dragResizeContainer = void 0;
        this._updateDragResizeContainer()
    }
    set fullScreen(fullScreen) {
        this._props.fullScreen = fullScreen;
        if (fullScreen) {
            this._fullScreenEnabled()
        } else {
            this._fullScreenDisabled()
        }
    }
    get $dragResizeContainer() {
        return this._$dragResizeContainer
    }
    get outsideDragFactor() {
        if (this._props.dragOutsideBoundary) {
            return 1
        }
        return this._props.outsideDragFactor
    }
    set dragAndResizeArea(dragAndResizeArea) {
        this._props.dragAndResizeArea = dragAndResizeArea;
        this._updateDragResizeContainer()
    }
    set dragOutsideBoundary(dragOutsideBoundary) {
        this._props.dragOutsideBoundary = dragOutsideBoundary;
        this._updateDragResizeContainer()
    }
    set outsideDragFactor(outsideDragFactor) {
        this._props.outsideDragFactor = outsideDragFactor
    }
    updateContainer(containerProp) {
        super.updateContainer(containerProp);
        this._updateDragResizeContainer()
    }
    dragHandled() {
        this.restorePositionOnNextRender(false)
    }
    resizeHandled() {
        this.restorePositionOnNextRender(false)
    }
    positionContent() {
        var _a, _b;
        if (this._props.fullScreen) {
            move(this._$content, {
                top: 0,
                left: 0
            });
            this.detectVisualPositionChange()
        } else {
            null === (_b = (_a = this._props).forceApplyBindings) || void 0 === _b ? void 0 : _b.call(_a);
            super.positionContent()
        }
    }
    _updateDragResizeContainer() {
        this._$dragResizeContainer = this._getDragResizeContainer()
    }
    _getDragResizeContainer() {
        if (this._props.dragOutsideBoundary) {
            return $(window)
        }
        if (this._props.dragAndResizeArea) {
            return $(this._props.dragAndResizeArea)
        }
        var isContainerDefined = originalViewPort().get(0) || this._props.container;
        return isContainerDefined ? this._$markupContainer : $(window)
    }
    _getVisualContainer() {
        if (this._props.fullScreen) {
            return $(window)
        }
        return super._getVisualContainer()
    }
    _fullScreenEnabled() {
        this.restorePositionOnNextRender(false)
    }
    _fullScreenDisabled() {
        this.restorePositionOnNextRender(true)
    }
}
export {
    PopupPositionController
};
