/**
 * DevExtreme (cjs/__internal/ui/popup/m_popup.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/
 */
"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
exports.default = void 0;
require("../../../ui/toolbar/ui.toolbar.base");
var _component_registrator = _interopRequireDefault(require("../../../core/component_registrator"));
var _devices = _interopRequireDefault(require("../../../core/devices"));
var _element = require("../../../core/element");
var _guid = _interopRequireDefault(require("../../../core/guid"));
var _renderer = _interopRequireDefault(require("../../../core/renderer"));
var _resize_observer = _interopRequireDefault(require("../../../core/resize_observer"));
var _empty_template = require("../../../core/templates/empty_template");
var _browser = _interopRequireDefault(require("../../../core/utils/browser"));
var _common = require("../../../core/utils/common");
var _extend = require("../../../core/utils/extend");
var _inflector = require("../../../core/utils/inflector");
var _iterator = require("../../../core/utils/iterator");
var _position = require("../../../core/utils/position");
var _size = require("../../../core/utils/size");
var _type = require("../../../core/utils/type");
var _version = require("../../../core/utils/version");
var _window = require("../../../core/utils/window");
var _visibility_change = require("../../../events/visibility_change");
var _message = _interopRequireDefault(require("../../../localization/message"));
var _button = _interopRequireDefault(require("../../../ui/button"));
var _ui = _interopRequireDefault(require("../../../ui/overlay/ui.overlay"));
var _resizable = _interopRequireDefault(require("../../../ui/resizable"));
var _themes = require("../../../ui/themes");
var zIndexPool = _interopRequireWildcard(require("../../ui/overlay/m_z_index"));
var _m_popup_drag = _interopRequireDefault(require("./m_popup_drag"));
var _m_popup_overflow_manager = require("./m_popup_overflow_manager");
var _m_popup_position_controller = require("./m_popup_position_controller");

function _getRequireWildcardCache(nodeInterop) {
    if ("function" !== typeof WeakMap) {
        return null
    }
    var cacheBabelInterop = new WeakMap;
    var cacheNodeInterop = new WeakMap;
    return (_getRequireWildcardCache = function(nodeInterop) {
        return nodeInterop ? cacheNodeInterop : cacheBabelInterop
    })(nodeInterop)
}

function _interopRequireWildcard(obj, nodeInterop) {
    if (!nodeInterop && obj && obj.__esModule) {
        return obj
    }
    if (null === obj || "object" !== typeof obj && "function" !== typeof obj) {
        return {
            default: obj
        }
    }
    var cache = _getRequireWildcardCache(nodeInterop);
    if (cache && cache.has(obj)) {
        return cache.get(obj)
    }
    var newObj = {};
    var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
    for (var key in obj) {
        if ("default" !== key && Object.prototype.hasOwnProperty.call(obj, key)) {
            var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
            if (desc && (desc.get || desc.set)) {
                Object.defineProperty(newObj, key, desc)
            } else {
                newObj[key] = obj[key]
            }
        }
    }
    newObj.default = obj;
    if (cache) {
        cache.set(obj, newObj)
    }
    return newObj
}

function _interopRequireDefault(obj) {
    return obj && obj.__esModule ? obj : {
        default: obj
    }
}
const window = (0, _window.getWindow)();
const POPUP_CLASS = "dx-popup";
const POPUP_WRAPPER_CLASS = "dx-popup-wrapper";
const POPUP_FULL_SCREEN_CLASS = "dx-popup-fullscreen";
const POPUP_FULL_SCREEN_WIDTH_CLASS = "dx-popup-fullscreen-width";
const POPUP_NORMAL_CLASS = "dx-popup-normal";
const POPUP_CONTENT_CLASS = "dx-popup-content";
const POPUP_CONTENT_SCROLLABLE_CLASS = "dx-popup-content-scrollable";
const DISABLED_STATE_CLASS = "dx-state-disabled";
const POPUP_DRAGGABLE_CLASS = "dx-popup-draggable";
const POPUP_TITLE_CLASS = "dx-popup-title";
const POPUP_TITLE_CLOSEBUTTON_CLASS = "dx-closebutton";
const POPUP_BOTTOM_CLASS = "dx-popup-bottom";
const POPUP_HAS_CLOSE_BUTTON_CLASS = "dx-has-close-button";
const TEMPLATE_WRAPPER_CLASS = "dx-template-wrapper";
const POPUP_CONTENT_FLEX_HEIGHT_CLASS = "dx-popup-flex-height";
const POPUP_CONTENT_INHERIT_HEIGHT_CLASS = "dx-popup-inherit-height";
const TOOLBAR_LABEL_CLASS = "dx-toolbar-label";
const ALLOWED_TOOLBAR_ITEM_ALIASES = ["cancel", "clear", "done"];
const BUTTON_DEFAULT_TYPE = "default";
const BUTTON_NORMAL_TYPE = "normal";
const BUTTON_TEXT_MODE = "text";
const BUTTON_CONTAINED_MODE = "contained";
const BUTTON_OUTLINED_MODE = "outlined";
const IS_OLD_SAFARI = _browser.default.safari && (0, _version.compare)(_browser.default.version, [11]) < 0;
const HEIGHT_STRATEGIES = {
    static: "",
    inherit: "dx-popup-inherit-height",
    flex: "dx-popup-flex-height"
};
const getButtonPlace = name => {
    const device = _devices.default.current();
    const {
        platform: platform
    } = device;
    let toolbar = "bottom";
    let location = "before";
    if ("ios" === platform) {
        switch (name) {
            case "cancel":
                toolbar = "top";
                break;
            case "clear":
                toolbar = "top";
                location = "after";
                break;
            case "done":
                location = "after"
        }
    } else if ("android" === platform) {
        switch (name) {
            case "cancel":
            case "done":
                location = "after"
        }
    }
    return {
        toolbar: toolbar,
        location: location
    }
};
const Popup = _ui.default.inherit({
    _supportedKeys() {
        return (0, _extend.extend)(this.callBase(), {
            upArrow: e => {
                var _a;
                null === (_a = this._drag) || void 0 === _a ? void 0 : _a.moveUp(e)
            },
            downArrow: e => {
                var _a;
                null === (_a = this._drag) || void 0 === _a ? void 0 : _a.moveDown(e)
            },
            leftArrow: e => {
                var _a;
                null === (_a = this._drag) || void 0 === _a ? void 0 : _a.moveLeft(e)
            },
            rightArrow: e => {
                var _a;
                null === (_a = this._drag) || void 0 === _a ? void 0 : _a.moveRight(e)
            }
        })
    },
    _getDefaultOptions() {
        return (0, _extend.extend)(this.callBase(), {
            fullScreen: false,
            title: "",
            showTitle: true,
            titleTemplate: "title",
            onTitleRendered: null,
            dragOutsideBoundary: false,
            dragEnabled: false,
            dragAndResizeArea: void 0,
            enableBodyScroll: true,
            outsideDragFactor: 0,
            onResizeStart: null,
            onResize: null,
            onResizeEnd: null,
            resizeEnabled: false,
            toolbarItems: [],
            showCloseButton: false,
            bottomTemplate: "bottom",
            useDefaultToolbarButtons: false,
            useFlatToolbarButtons: false,
            autoResizeEnabled: true
        })
    },
    _defaultOptionsRules() {
        return this.callBase().concat([{
            device: {
                platform: "ios"
            },
            options: {
                animation: this._iosAnimation
            }
        }, {
            device: {
                platform: "android"
            },
            options: {
                animation: this._androidAnimation
            }
        }, {
            device: {
                platform: "generic"
            },
            options: {
                showCloseButton: true
            }
        }, {
            device: device => "desktop" === _devices.default.real().deviceType && "generic" === device.platform,
            options: {
                dragEnabled: true
            }
        }, {
            device: () => "desktop" === _devices.default.real().deviceType && !_devices.default.isSimulator(),
            options: {
                focusStateEnabled: true
            }
        }, {
            device: () => (0, _themes.isMaterialBased)(),
            options: {
                useFlatToolbarButtons: true
            }
        }, {
            device: () => (0, _themes.isMaterial)(),
            options: {
                useDefaultToolbarButtons: true,
                showCloseButton: false
            }
        }])
    },
    _iosAnimation: {
        show: {
            type: "slide",
            duration: 400,
            from: {
                position: {
                    my: "top",
                    at: "bottom"
                }
            },
            to: {
                position: {
                    my: "center",
                    at: "center"
                }
            }
        },
        hide: {
            type: "slide",
            duration: 400,
            from: {
                opacity: 1,
                position: {
                    my: "center",
                    at: "center"
                }
            },
            to: {
                opacity: 1,
                position: {
                    my: "top",
                    at: "bottom"
                }
            }
        }
    },
    _androidAnimation() {
        return this.option("fullScreen") ? {
            show: {
                type: "slide",
                duration: 300,
                from: {
                    top: "30%",
                    opacity: 0
                },
                to: {
                    top: 0,
                    opacity: 1
                }
            },
            hide: {
                type: "slide",
                duration: 300,
                from: {
                    top: 0,
                    opacity: 1
                },
                to: {
                    top: "30%",
                    opacity: 0
                }
            }
        } : {
            show: {
                type: "fade",
                duration: 400,
                from: 0,
                to: 1
            },
            hide: {
                type: "fade",
                duration: 400,
                from: 1,
                to: 0
            }
        }
    },
    _init() {
        const popupWrapperClassExternal = this.option("_wrapperClassExternal");
        const popupWrapperClasses = popupWrapperClassExternal ? "".concat("dx-popup-wrapper", " ").concat(popupWrapperClassExternal) : "dx-popup-wrapper";
        this.callBase();
        this._createBodyOverflowManager();
        this._updateResizeCallbackSkipCondition();
        this.$element().addClass("dx-popup");
        this.$wrapper().addClass(popupWrapperClasses);
        this._$popupContent = this._$content.wrapInner((0, _renderer.default)("<div>").addClass("dx-popup-content")).children().eq(0);
        this._toggleContentScrollClass();
        this.$overlayContent().attr("role", "dialog")
    },
    _render() {
        const isFullscreen = this.option("fullScreen");
        this._toggleFullScreenClass(isFullscreen);
        this.callBase()
    },
    _createBodyOverflowManager() {
        this._bodyOverflowManager = (0, _m_popup_overflow_manager.createBodyOverflowManager)()
    },
    _toggleFullScreenClass(value) {
        this.$overlayContent().toggleClass("dx-popup-fullscreen", value).toggleClass("dx-popup-normal", !value)
    },
    _initTemplates() {
        this.callBase();
        this._templateManager.addDefaultTemplates({
            title: new _empty_template.EmptyTemplate,
            bottom: new _empty_template.EmptyTemplate
        })
    },
    _getActionsList() {
        return this.callBase().concat(["onResizeStart", "onResize", "onResizeEnd"])
    },
    _contentResizeHandler(entry) {
        if (!this._shouldSkipContentResize(entry)) {
            this._renderGeometry({
                shouldOnlyReposition: true
            })
        }
    },
    _doesShowAnimationChangeDimensions() {
        const animation = this.option("animation");
        return ["to", "from"].some(prop => {
            var _a;
            const config = null === (_a = null === animation || void 0 === animation ? void 0 : animation.show) || void 0 === _a ? void 0 : _a[prop];
            return (0, _type.isObject)(config) && ("width" in config || "height" in config)
        })
    },
    _updateResizeCallbackSkipCondition() {
        const doesShowAnimationChangeDimensions = this._doesShowAnimationChangeDimensions();
        this._shouldSkipContentResize = entry => doesShowAnimationChangeDimensions && this._showAnimationProcessing || this._areContentDimensionsRendered(entry)
    },
    _observeContentResize(shouldObserve) {
        if (!this.option("useResizeObserver")) {
            return
        }
        const contentElement = this._$content.get(0);
        if (shouldObserve) {
            _resize_observer.default.observe(contentElement, entry => {
                this._contentResizeHandler(entry)
            })
        } else {
            _resize_observer.default.unobserve(contentElement)
        }
    },
    _areContentDimensionsRendered(entry) {
        var _a, _b, _c, _d, _e;
        const contentBox = null === (_a = entry.contentBoxSize) || void 0 === _a ? void 0 : _a[0];
        if (contentBox) {
            return parseInt(contentBox.inlineSize, 10) === (null === (_b = this._renderedDimensions) || void 0 === _b ? void 0 : _b.width) && parseInt(contentBox.blockSize, 10) === (null === (_c = this._renderedDimensions) || void 0 === _c ? void 0 : _c.height)
        }
        const {
            contentRect: contentRect
        } = entry;
        return parseInt(contentRect.width, 10) === (null === (_d = this._renderedDimensions) || void 0 === _d ? void 0 : _d.width) && parseInt(contentRect.height, 10) === (null === (_e = this._renderedDimensions) || void 0 === _e ? void 0 : _e.height)
    },
    _renderContent() {
        this.callBase();
        this._observeContentResize(true)
    },
    _renderContentImpl() {
        this._renderTitle();
        this.callBase();
        this._renderResize();
        this._renderBottom()
    },
    _renderTitle() {
        const items = this._getToolbarItems("top");
        const {
            title: title,
            showTitle: showTitle
        } = this.option();
        if (showTitle && !!title) {
            items.unshift({
                location: _devices.default.current().ios ? "center" : "before",
                text: title
            })
        }
        if (showTitle || items.length > 0) {
            this._$title && this._$title.remove();
            const $title = (0, _renderer.default)("<div>").addClass("dx-popup-title").insertBefore(this.$content());
            this._$title = this._renderTemplateByType("titleTemplate", items, $title).addClass("dx-popup-title");
            this._renderDrag();
            this._executeTitleRenderAction(this._$title);
            this._$title.toggleClass("dx-has-close-button", this._hasCloseButton())
        } else if (this._$title) {
            this._$title.detach()
        }
        this._toggleAriaLabel()
    },
    _toggleAriaLabel() {
        var _a;
        const {
            title: title,
            showTitle: showTitle
        } = this.option();
        const shouldSetAriaLabel = showTitle && !!title;
        const titleId = shouldSetAriaLabel ? new _guid.default : null;
        null === (_a = this._$title) || void 0 === _a ? void 0 : _a.find(".".concat("dx-toolbar-label")).eq(0).attr("id", titleId);
        this.$overlayContent().attr("aria-labelledby", titleId)
    },
    _renderTemplateByType(optionName, data, $container, additionalToolbarOptions) {
        const {
            rtlEnabled: rtlEnabled,
            useDefaultToolbarButtons: useDefaultToolbarButtons,
            useFlatToolbarButtons: useFlatToolbarButtons,
            disabled: disabled
        } = this.option();
        const template = this._getTemplateByOption(optionName);
        const toolbarTemplate = template instanceof _empty_template.EmptyTemplate;
        if (toolbarTemplate) {
            const integrationOptions = (0, _extend.extend)({}, this.option("integrationOptions"), {
                skipTemplates: ["content", "title"]
            });
            const toolbarOptions = (0, _extend.extend)(additionalToolbarOptions, {
                items: data,
                rtlEnabled: rtlEnabled,
                useDefaultButtons: useDefaultToolbarButtons,
                useFlatButtons: useFlatToolbarButtons,
                disabled: disabled,
                integrationOptions: integrationOptions
            });
            this._getTemplate("dx-polymorph-widget").render({
                container: $container,
                model: {
                    widget: this._getToolbarName(),
                    options: toolbarOptions
                }
            });
            const $toolbar = $container.children("div");
            $container.replaceWith($toolbar);
            return $toolbar
        }
        const $result = (0, _renderer.default)(template.render({
            container: (0, _element.getPublicElement)($container)
        }));
        if ($result.hasClass("dx-template-wrapper")) {
            $container.replaceWith($result);
            $container = $result
        }
        return $container
    },
    _getToolbarName: () => "dxToolbarBase",
    _renderVisibilityAnimate(visible) {
        return this.callBase(visible)
    },
    _hide() {
        this._observeContentResize(false);
        return this.callBase()
    },
    _executeTitleRenderAction($titleElement) {
        this._getTitleRenderAction()({
            titleElement: (0, _element.getPublicElement)($titleElement)
        })
    },
    _getTitleRenderAction() {
        return this._titleRenderAction || this._createTitleRenderAction()
    },
    _createTitleRenderAction() {
        return this._titleRenderAction = this._createActionByOption("onTitleRendered", {
            element: this.element(),
            excludeValidators: ["disabled", "readOnly"]
        })
    },
    _getCloseButton() {
        return {
            toolbar: "top",
            location: "after",
            template: this._getCloseButtonRenderer()
        }
    },
    _getCloseButtonRenderer() {
        return (_, __, container) => {
            const $button = (0, _renderer.default)("<div>").addClass("dx-closebutton");
            this._createComponent($button, _button.default, {
                icon: "close",
                onClick: this._createToolbarItemAction(void 0),
                stylingMode: "text",
                integrationOptions: {}
            });
            (0, _renderer.default)(container).append($button)
        }
    },
    _getToolbarItems(toolbar) {
        const toolbarItems = this.option("toolbarItems");
        const toolbarsItems = [];
        this._toolbarItemClasses = [];
        const currentPlatform = _devices.default.current().platform;
        let index = 0;
        (0, _iterator.each)(toolbarItems, (_, data) => {
            const isShortcut = (0, _type.isDefined)(data.shortcut);
            const item = isShortcut ? getButtonPlace(data.shortcut) : data;
            if (isShortcut && "ios" === currentPlatform && index < 2) {
                item.toolbar = "top";
                index++
            }
            item.toolbar = data.toolbar || item.toolbar || "top";
            if (item && item.toolbar === toolbar) {
                if (isShortcut) {
                    (0, _extend.extend)(item, {
                        location: data.location
                    }, this._getToolbarItemByAlias(data))
                }
                const isLTROrder = "generic" === currentPlatform;
                if ("done" === data.shortcut && isLTROrder || "cancel" === data.shortcut && !isLTROrder) {
                    toolbarsItems.unshift(item)
                } else {
                    toolbarsItems.push(item)
                }
            }
        });
        if ("top" === toolbar && this._hasCloseButton()) {
            toolbarsItems.push(this._getCloseButton())
        }
        return toolbarsItems
    },
    _hasCloseButton() {
        return this.option("showCloseButton") && this.option("showTitle")
    },
    _getLocalizationKey: itemType => "done" === itemType.toLowerCase() ? "OK" : (0, _inflector.camelize)(itemType, true),
    _getToolbarButtonStylingMode(shortcut) {
        if ((0, _themes.isFluent)()) {
            return "done" === shortcut ? "contained" : "outlined"
        }
        return this.option("useFlatToolbarButtons") ? "text" : "contained"
    },
    _getToolbarButtonType(shortcut) {
        if ((0, _themes.isFluent)() && "done" === shortcut || this.option("useDefaultToolbarButtons")) {
            return "default"
        }
        return "normal"
    },
    _getToolbarItemByAlias(data) {
        const that = this;
        const itemType = data.shortcut;
        if (!ALLOWED_TOOLBAR_ITEM_ALIASES.includes(itemType)) {
            return false
        }
        const itemConfig = (0, _extend.extend)({
            text: _message.default.format(this._getLocalizationKey(itemType)),
            onClick: this._createToolbarItemAction(data.onClick),
            integrationOptions: {},
            type: this._getToolbarButtonType(itemType),
            stylingMode: this._getToolbarButtonStylingMode(itemType)
        }, data.options || {});
        const itemClass = "".concat("dx-popup", "-").concat(itemType);
        this._toolbarItemClasses.push(itemClass);
        return {
            template(_, __, container) {
                const $toolbarItem = (0, _renderer.default)("<div>").addClass(itemClass).appendTo(container);
                that._createComponent($toolbarItem, _button.default, itemConfig)
            }
        }
    },
    _createToolbarItemAction(clickAction) {
        return this._createAction(clickAction, {
            afterExecute(e) {
                e.component.hide()
            }
        })
    },
    _renderBottom() {
        const items = this._getToolbarItems("bottom");
        if (items.length) {
            this._$bottom && this._$bottom.remove();
            const $bottom = (0, _renderer.default)("<div>").addClass("dx-popup-bottom").insertAfter(this.$content());
            this._$bottom = this._renderTemplateByType("bottomTemplate", items, $bottom, {
                compactMode: true
            }).addClass("dx-popup-bottom");
            this._toggleClasses()
        } else {
            this._$bottom && this._$bottom.detach()
        }
    },
    _toggleDisabledState(value) {
        this.callBase(...arguments);
        this.$content().toggleClass("dx-state-disabled", Boolean(value))
    },
    _toggleClasses() {
        const aliases = ALLOWED_TOOLBAR_ITEM_ALIASES;
        (0, _iterator.each)(aliases, (_, alias) => {
            const className = "".concat("dx-popup", "-").concat(alias);
            if (this._toolbarItemClasses.includes(className)) {
                this.$wrapper().addClass("".concat(className, "-visible"));
                this._$bottom.addClass(className)
            } else {
                this.$wrapper().removeClass("".concat(className, "-visible"));
                this._$bottom.removeClass(className)
            }
        })
    },
    _toggleFocusClass(isFocused, $element) {
        this.callBase(isFocused, $element);
        if (isFocused && !zIndexPool.isLastZIndexInStack(this._zIndex)) {
            const zIndex = zIndexPool.create(this._zIndexInitValue());
            zIndexPool.remove(this._zIndex);
            this._zIndex = zIndex;
            this._$wrapper.css("zIndex", zIndex);
            this._$content.css("zIndex", zIndex)
        }
    },
    _toggleContentScrollClass() {
        const isNativeScrollingEnabled = !this.option("preventScrollEvents");
        this.$content().toggleClass("dx-popup-content-scrollable", isNativeScrollingEnabled)
    },
    _getPositionControllerConfig() {
        const {
            fullScreen: fullScreen,
            forceApplyBindings: forceApplyBindings,
            dragOutsideBoundary: dragOutsideBoundary,
            dragAndResizeArea: dragAndResizeArea,
            outsideDragFactor: outsideDragFactor
        } = this.option();
        return (0, _extend.extend)({}, this.callBase(), {
            fullScreen: fullScreen,
            forceApplyBindings: forceApplyBindings,
            dragOutsideBoundary: dragOutsideBoundary,
            dragAndResizeArea: dragAndResizeArea,
            outsideDragFactor: outsideDragFactor
        })
    },
    _initPositionController() {
        this._positionController = new _m_popup_position_controller.PopupPositionController(this._getPositionControllerConfig())
    },
    _getDragTarget() {
        return this.topToolbar()
    },
    _renderGeometry(options) {
        const {
            visible: visible,
            useResizeObserver: useResizeObserver
        } = this.option();
        if (visible && (0, _window.hasWindow)()) {
            const isAnimated = this._showAnimationProcessing;
            const shouldRepeatAnimation = isAnimated && !(null === options || void 0 === options ? void 0 : options.forceStopAnimation) && useResizeObserver;
            this._isAnimationPaused = shouldRepeatAnimation || void 0;
            this._stopAnimation();
            if (null === options || void 0 === options ? void 0 : options.shouldOnlyReposition) {
                this._renderPosition(false)
            } else {
                this._renderGeometryImpl(null === options || void 0 === options ? void 0 : options.isDimensionChange)
            }
            if (shouldRepeatAnimation) {
                this._animateShowing();
                this._isAnimationPaused = void 0
            }
        }
    },
    _cacheDimensions() {
        if (!this.option("useResizeObserver")) {
            return
        }
        this._renderedDimensions = {
            width: parseInt((0, _size.getWidth)(this._$content), 10),
            height: parseInt((0, _size.getHeight)(this._$content), 10)
        }
    },
    _renderGeometryImpl() {
        let isDimensionChange = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : false;
        if (!isDimensionChange) {
            this._resetContentHeight()
        }
        this.callBase();
        this._cacheDimensions();
        this._setContentHeight()
    },
    _resetContentHeight() {
        const height = this._getOptionValue("height");
        if ("auto" === height) {
            this.$content().css({
                height: "auto",
                maxHeight: "none"
            })
        }
    },
    _renderDrag() {
        const $dragTarget = this._getDragTarget();
        const dragEnabled = this.option("dragEnabled");
        if (!$dragTarget) {
            return
        }
        const config = {
            dragEnabled: dragEnabled,
            handle: $dragTarget.get(0),
            draggableElement: this._$content.get(0),
            positionController: this._positionController
        };
        if (this._drag) {
            this._drag.init(config)
        } else {
            this._drag = new _m_popup_drag.default(config)
        }
        this.$overlayContent().toggleClass("dx-popup-draggable", dragEnabled)
    },
    _renderResize() {
        this._resizable = this._createComponent(this._$content, _resizable.default, {
            handles: this.option("resizeEnabled") ? "all" : "none",
            onResizeEnd: e => {
                this._resizeEndHandler(e);
                this._observeContentResize(true)
            },
            onResize: e => {
                this._setContentHeight();
                this._actions.onResize(e)
            },
            onResizeStart: e => {
                this._observeContentResize(false);
                this._actions.onResizeStart(e)
            },
            minHeight: 100,
            minWidth: 100,
            area: this._positionController.$dragResizeContainer,
            keepAspectRatio: false
        })
    },
    _resizeEndHandler(e) {
        const width = this._resizable.option("width");
        const height = this._resizable.option("height");
        width && this._setOptionWithoutOptionChange("width", width);
        height && this._setOptionWithoutOptionChange("height", height);
        this._cacheDimensions();
        this._positionController.resizeHandled();
        this._positionController.detectVisualPositionChange(e.event);
        this._actions.onResizeEnd(e)
    },
    _setContentHeight() {
        (this.option("forceApplyBindings") || _common.noop)();
        const overlayContent = this.$overlayContent().get(0);
        const currentHeightStrategyClass = this._chooseHeightStrategy(overlayContent);
        this.$content().css(this._getHeightCssStyles(currentHeightStrategyClass, overlayContent));
        this._setHeightClasses(this.$overlayContent(), currentHeightStrategyClass)
    },
    _heightStrategyChangeOffset: (currentHeightStrategyClass, popupVerticalPaddings) => currentHeightStrategyClass === HEIGHT_STRATEGIES.flex ? -popupVerticalPaddings : 0,
    _chooseHeightStrategy(overlayContent) {
        const isAutoWidth = "auto" === overlayContent.style.width || "" === overlayContent.style.width;
        let currentHeightStrategyClass = HEIGHT_STRATEGIES.static;
        if (this._isAutoHeight() && this.option("autoResizeEnabled")) {
            if (isAutoWidth || IS_OLD_SAFARI) {
                currentHeightStrategyClass = HEIGHT_STRATEGIES.inherit
            } else {
                currentHeightStrategyClass = HEIGHT_STRATEGIES.flex
            }
        }
        return currentHeightStrategyClass
    },
    _getHeightCssStyles(currentHeightStrategyClass, overlayContent) {
        let cssStyles = {};
        const contentMaxHeight = this._getOptionValue("maxHeight", overlayContent);
        const contentMinHeight = this._getOptionValue("minHeight", overlayContent);
        const popupHeightParts = this._splitPopupHeight();
        const toolbarsAndVerticalOffsetsHeight = popupHeightParts.header + popupHeightParts.footer + popupHeightParts.contentVerticalOffsets + popupHeightParts.popupVerticalOffsets + this._heightStrategyChangeOffset(currentHeightStrategyClass, popupHeightParts.popupVerticalPaddings);
        if (currentHeightStrategyClass === HEIGHT_STRATEGIES.static) {
            if (!this._isAutoHeight() || contentMaxHeight || contentMinHeight) {
                const overlayHeight = this.option("fullScreen") ? Math.min((0, _position.getBoundingRect)(overlayContent).height, (0, _window.getWindow)().innerHeight) : (0, _position.getBoundingRect)(overlayContent).height;
                const contentHeight = overlayHeight - toolbarsAndVerticalOffsetsHeight;
                cssStyles = {
                    height: Math.max(0, contentHeight),
                    minHeight: "auto",
                    maxHeight: "auto"
                }
            }
        } else {
            const container = (0, _renderer.default)(this._positionController.$visualContainer).get(0);
            const maxHeightValue = (0, _size.addOffsetToMaxHeight)(contentMaxHeight, -toolbarsAndVerticalOffsetsHeight, container);
            const minHeightValue = (0, _size.addOffsetToMinHeight)(contentMinHeight, -toolbarsAndVerticalOffsetsHeight, container);
            cssStyles = {
                height: "auto",
                minHeight: minHeightValue,
                maxHeight: maxHeightValue
            }
        }
        return cssStyles
    },
    _setHeightClasses($container, currentClass) {
        let excessClasses = "";
        for (const name in HEIGHT_STRATEGIES) {
            if (HEIGHT_STRATEGIES[name] !== currentClass) {
                excessClasses += " ".concat(HEIGHT_STRATEGIES[name])
            }
        }
        $container.removeClass(excessClasses).addClass(currentClass)
    },
    _isAutoHeight() {
        return "auto" === this.$overlayContent().get(0).style.height
    },
    _splitPopupHeight() {
        const topToolbar = this.topToolbar();
        const bottomToolbar = this.bottomToolbar();
        return {
            header: (0, _size.getVisibleHeight)(topToolbar && topToolbar.get(0)),
            footer: (0, _size.getVisibleHeight)(bottomToolbar && bottomToolbar.get(0)),
            contentVerticalOffsets: (0, _size.getVerticalOffsets)(this.$overlayContent().get(0), true),
            popupVerticalOffsets: (0, _size.getVerticalOffsets)(this.$content().get(0), true),
            popupVerticalPaddings: (0, _size.getVerticalOffsets)(this.$content().get(0), false)
        }
    },
    _isAllWindowCovered() {
        return this.callBase() || this.option("fullScreen")
    },
    _renderDimensions() {
        if (this.option("fullScreen")) {
            this.$overlayContent().css({
                width: "100%",
                height: "100%",
                minWidth: "",
                maxWidth: "",
                minHeight: "",
                maxHeight: ""
            })
        } else {
            this.callBase()
        }
        if ((0, _window.hasWindow)()) {
            this._renderFullscreenWidthClass()
        }
    },
    _dimensionChanged() {
        this._renderGeometry({
            isDimensionChange: true
        })
    },
    _clean() {
        this.callBase();
        this._observeContentResize(false)
    },
    _dispose() {
        this.callBase();
        this._toggleBodyScroll(true)
    },
    _renderFullscreenWidthClass() {
        this.$overlayContent().toggleClass("dx-popup-fullscreen-width", (0, _size.getOuterWidth)(this.$overlayContent()) === (0, _size.getWidth)(window))
    },
    _toggleSafariScrolling() {
        if (!this.option("enableBodyScroll")) {
            return
        }
        this.callBase()
    },
    _toggleBodyScroll(enabled) {
        if (!this._bodyOverflowManager) {
            return
        }
        const {
            setOverflow: setOverflow,
            restoreOverflow: restoreOverflow
        } = this._bodyOverflowManager;
        if (enabled) {
            restoreOverflow()
        } else {
            setOverflow()
        }
    },
    refreshPosition() {
        this._renderPosition()
    },
    _optionChanged(args) {
        var _a, _b;
        const {
            value: value,
            name: name
        } = args;
        switch (name) {
            case "disabled":
                this.callBase(args);
                this._renderTitle();
                this._renderBottom();
                break;
            case "animation":
                this._updateResizeCallbackSkipCondition();
                break;
            case "enableBodyScroll":
                if (this.option("visible")) {
                    this._toggleBodyScroll(value)
                }
                break;
            case "showTitle":
            case "title":
            case "titleTemplate":
                this._renderTitle();
                this._renderGeometry();
                (0, _visibility_change.triggerResizeEvent)(this.$overlayContent());
                break;
            case "bottomTemplate":
                this._renderBottom();
                this._renderGeometry();
                (0, _visibility_change.triggerResizeEvent)(this.$overlayContent());
                break;
            case "container":
                this.callBase(args);
                if (this.option("resizeEnabled")) {
                    null === (_a = this._resizable) || void 0 === _a ? void 0 : _a.option("area", this._positionController.$dragResizeContainer)
                }
                break;
            case "width":
            case "height":
                this.callBase(args);
                null === (_b = this._resizable) || void 0 === _b ? void 0 : _b.option(name, value);
                break;
            case "onTitleRendered":
                this._createTitleRenderAction(value);
                break;
            case "toolbarItems":
            case "useDefaultToolbarButtons":
            case "useFlatToolbarButtons": {
                const shouldRenderGeometry = !args.fullName.match(/^toolbarItems((\[\d+\])(\.(options|visible).*)?)?$/);
                this._renderTitle();
                this._renderBottom();
                if (shouldRenderGeometry) {
                    this._renderGeometry();
                    (0, _visibility_change.triggerResizeEvent)(this.$overlayContent())
                }
                break
            }
            case "dragEnabled":
                this._renderDrag();
                break;
            case "dragAndResizeArea":
                this._positionController.dragAndResizeArea = value;
                if (this.option("resizeEnabled")) {
                    this._resizable.option("area", this._positionController.$dragResizeContainer)
                }
                this._positionController.positionContent();
                break;
            case "dragOutsideBoundary":
                this._positionController.dragOutsideBoundary = value;
                if (this.option("resizeEnabled")) {
                    this._resizable.option("area", this._positionController.$dragResizeContainer)
                }
                break;
            case "outsideDragFactor":
                this._positionController.outsideDragFactor = value;
                break;
            case "resizeEnabled":
                this._renderResize();
                this._renderGeometry();
                break;
            case "autoResizeEnabled":
                this._renderGeometry();
                (0, _visibility_change.triggerResizeEvent)(this.$overlayContent());
                break;
            case "fullScreen":
                this._positionController.fullScreen = value;
                this._toggleFullScreenClass(value);
                this._toggleSafariScrolling();
                this._renderGeometry();
                (0, _visibility_change.triggerResizeEvent)(this.$overlayContent());
                break;
            case "showCloseButton":
                this._renderTitle();
                break;
            case "preventScrollEvents":
                this.callBase(args);
                this._toggleContentScrollClass();
                break;
            default:
                this.callBase(args)
        }
    },
    bottomToolbar() {
        return this._$bottom
    },
    topToolbar() {
        return this._$title
    },
    $content() {
        return this._$popupContent
    },
    content() {
        return (0, _element.getPublicElement)(this.$content())
    },
    $overlayContent() {
        return this._$content
    },
    getFocusableElements() {
        return this.$wrapper().find("[tabindex]").filter((index, item) => item.getAttribute("tabindex") >= 0)
    }
});
(0, _component_registrator.default)("dxPopup", Popup);
var _default = Popup;
exports.default = _default;
