/**
 * DevExtreme (cjs/__internal/grids/grid_core/views/m_grid_view.js)
 * Version: 23.1.8 (build 24063-0109)
 * Build date: Sun Mar 03 2024
 *
 * Copyright (c) 2012 - 2024 Developer Express Inc. ALL RIGHTS RESERVED
 * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
 */
"use strict";

function _typeof(obj) {
    return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(obj) {
        return typeof obj
    } : function(obj) {
        return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj
    }, _typeof(obj)
}
Object.defineProperty(exports, "__esModule", {
    value: true
});
exports.gridViewModule = exports.ResizingController = void 0;
var _dom_adapter = _interopRequireDefault(require("../../../../core/dom_adapter"));
var _renderer = _interopRequireDefault(require("../../../../core/renderer"));
var _browser = _interopRequireDefault(require("../../../../core/utils/browser"));
var _common = require("../../../../core/utils/common");
var _deferred = require("../../../../core/utils/deferred");
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 _window = require("../../../../core/utils/window");
var _message = _interopRequireDefault(require("../../../../localization/message"));
var accessibility = _interopRequireWildcard(require("../../../../ui/shared/accessibility"));
var _m_modules = _interopRequireDefault(require("../m_modules"));
var _m_utils = _interopRequireDefault(require("../m_utils"));

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
    }
}

function _inheritsLoose(subClass, superClass) {
    subClass.prototype = Object.create(superClass.prototype);
    subClass.prototype.constructor = subClass;
    _setPrototypeOf(subClass, superClass)
}

function _setPrototypeOf(o, p) {
    _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function(o, p) {
        o.__proto__ = p;
        return o
    };
    return _setPrototypeOf(o, p)
}
var BORDERS_CLASS = "borders";
var TABLE_FIXED_CLASS = "table-fixed";
var IMPORTANT_MARGIN_CLASS = "important-margin";
var GRIDBASE_CONTAINER_CLASS = "dx-gridbase-container";
var GROUP_ROW_SELECTOR = "tr.dx-group-row";
var HIDDEN_COLUMNS_WIDTH = "adaptiveHidden";
var VIEW_NAMES = ["columnsSeparatorView", "blockSeparatorView", "trackerView", "headerPanel", "columnHeadersView", "rowsView", "footerView", "columnChooserView", "filterPanelView", "pagerView", "draggingHeaderView", "contextMenuView", "errorView", "headerFilterView", "filterBuilderView"];
var isPercentWidth = function(width) {
    return (0, _type.isString)(width) && width.endsWith("%")
};
var isPixelWidth = function(width) {
    return (0, _type.isString)(width) && width.endsWith("px")
};
var calculateFreeWidth = function(that, widths) {
    var contentWidth = that._rowsView.contentWidth();
    var totalWidth = that._getTotalWidth(widths, contentWidth);
    return contentWidth - totalWidth
};
var calculateFreeWidthWithCurrentMinWidth = function(that, columnIndex, currentMinWidth, widths) {
    return calculateFreeWidth(that, widths.map((function(width, index) {
        return index === columnIndex ? currentMinWidth : width
    })))
};
var restoreFocus = function(focusedElement, selectionRange) {
    accessibility.hiddenFocus(focusedElement, true);
    _m_utils.default.setSelectionRange(focusedElement, selectionRange)
};
var ResizingController = function(_modules$ViewControll) {
    _inheritsLoose(ResizingController, _modules$ViewControll);

    function ResizingController() {
        return _modules$ViewControll.apply(this, arguments) || this
    }
    var _proto = ResizingController.prototype;
    _proto._initPostRenderHandlers = function() {
        var _this = this;
        if (!this._refreshSizesHandler) {
            this._refreshSizesHandler = function(e) {
                var resizeDeferred = (new _deferred.Deferred).resolve(null);
                var changeType = null === e || void 0 === e ? void 0 : e.changeType;
                var isDelayed = null === e || void 0 === e ? void 0 : e.isDelayed;
                var needFireContentReady = changeType && "updateSelection" !== changeType && "updateFocusedRow" !== changeType && "pageIndex" !== changeType && !isDelayed;
                _this._dataController.changed.remove(_this._refreshSizesHandler);
                if (_this._checkSize()) {
                    resizeDeferred = _this._refreshSizes(e)
                }
                if (needFireContentReady) {
                    (0, _deferred.when)(resizeDeferred).done((function() {
                        _this._setAriaLabel();
                        _this.fireContentReadyAction()
                    }))
                }
            };
            this._dataController.changed.add((function() {
                _this._dataController.changed.add(_this._refreshSizesHandler)
            }))
        }
    };
    _proto._refreshSizes = function(e) {
        var _this2 = this;
        var _a;
        var resizeDeferred = (new _deferred.Deferred).resolve(null);
        var changeType = null === e || void 0 === e ? void 0 : e.changeType;
        var isDelayed = null === e || void 0 === e ? void 0 : e.isDelayed;
        var items = this._dataController.items();
        if (!e || "refresh" === changeType || "prepend" === changeType || "append" === changeType) {
            if (!isDelayed) {
                resizeDeferred = this.resize()
            }
        } else if ("update" === changeType) {
            if (0 === (null === (_a = e.changeTypes) || void 0 === _a ? void 0 : _a.length)) {
                return resizeDeferred
            }
            if ((items.length > 1 || "insert" !== e.changeTypes[0]) && !(0 === items.length && "remove" === e.changeTypes[0]) && !e.needUpdateDimensions) {
                resizeDeferred = new _deferred.Deferred;
                this._waitAsyncTemplates().done((function() {
                    (0, _common.deferUpdate)((function() {
                        return (0, _common.deferRender)((function() {
                            return (0, _common.deferUpdate)((function() {
                                _this2._setScrollerSpacing();
                                _this2._rowsView.resize();
                                resizeDeferred.resolve()
                            }))
                        }))
                    }))
                })).fail(resizeDeferred.reject)
            } else {
                resizeDeferred = this.resize()
            }
        }
        return resizeDeferred
    };
    _proto.fireContentReadyAction = function() {
        this.component._fireContentReadyAction()
    };
    _proto._getWidgetAriaLabel = function() {
        return "dxDataGrid-ariaDataGrid"
    };
    _proto._setAriaLabel = function() {
        var totalItemsCount = Math.max(0, this._dataController.totalItemsCount());
        this.component.setAria("label", _message.default.format(this._getWidgetAriaLabel(), totalItemsCount, this.component.columnCount()), this.component.$element().children(".".concat(GRIDBASE_CONTAINER_CLASS)))
    };
    _proto._getBestFitWidths = function() {
        var _a;
        var rowsView = this._rowsView;
        var columnHeadersView = this._columnHeadersView;
        var widths = rowsView.getColumnWidths();
        if (!(null === widths || void 0 === widths ? void 0 : widths.length)) {
            var headersTableElement = columnHeadersView.getTableElement();
            columnHeadersView.setTableElement(null === (_a = rowsView.getTableElement()) || void 0 === _a ? void 0 : _a.children(".dx-header"));
            widths = columnHeadersView.getColumnWidths();
            columnHeadersView.setTableElement(headersTableElement)
        }
        return widths
    };
    _proto._setVisibleWidths = function(visibleColumns, widths) {
        var columnsController = this._columnsController;
        columnsController.beginUpdate();
        (0, _iterator.each)(visibleColumns, (function(index, column) {
            var columnId = columnsController.getColumnId(column);
            columnsController.columnOption(columnId, "visibleWidth", widths[index])
        }));
        columnsController.endUpdate()
    };
    _proto._toggleBestFitModeForView = function(view, className, isBestFit) {
        var _this3 = this;
        if (!view || !view.isVisible()) {
            return
        }
        var $rowsTables = this._rowsView.getTableElements();
        var $viewTables = view.getTableElements();
        (0, _iterator.each)($rowsTables, (function(index, tableElement) {
            var $tableBody;
            var $rowsTable = (0, _renderer.default)(tableElement);
            var $viewTable = $viewTables.eq(index);
            if ($viewTable && $viewTable.length) {
                if (isBestFit) {
                    $tableBody = $viewTable.children("tbody").appendTo($rowsTable)
                } else {
                    $tableBody = $rowsTable.children(".".concat(className)).appendTo($viewTable)
                }
                $tableBody.toggleClass(className, isBestFit);
                $tableBody.toggleClass(_this3.addWidgetPrefix("best-fit"), isBestFit)
            }
        }))
    };
    _proto._toggleBestFitMode = function(isBestFit) {
        var $rowsTable = this._rowsView.getTableElement();
        var $rowsFixedTable = this._rowsView.getTableElements().eq(1);
        if (!$rowsTable) {
            return
        }
        $rowsTable.css("tableLayout", isBestFit ? "auto" : "fixed");
        $rowsTable.children("colgroup").css("display", isBestFit ? "none" : "");
        (0, _iterator.each)($rowsFixedTable.find(GROUP_ROW_SELECTOR), (function(idx, item) {
            (0, _renderer.default)(item).css("display", isBestFit ? "none" : "")
        }));
        $rowsFixedTable.toggleClass(this.addWidgetPrefix(TABLE_FIXED_CLASS), !isBestFit);
        this._toggleBestFitModeForView(this._columnHeadersView, "dx-header", isBestFit);
        this._toggleBestFitModeForView(this._footerView, "dx-footer", isBestFit);
        if (this._needStretch()) {
            $rowsTable.get(0).style.width = isBestFit ? "auto" : ""
        }
    };
    _proto._toggleContentMinHeight = function(value) {
        var scrollable = this._rowsView.getScrollable();
        var $contentElement = this._rowsView._findContentElement();
        if (false === (null === scrollable || void 0 === scrollable ? void 0 : scrollable.option("useNative"))) {
            if (true === value) {
                this._prevContentMinHeight = $contentElement.get(0).style.minHeight
            }
            if ((0, _type.isDefined)(this._prevContentMinHeight)) {
                $contentElement.css({
                    minHeight: value ? _m_utils.default.getContentHeightLimit(_browser.default) : this._prevContentMinHeight
                })
            }
        }
    };
    _proto._synchronizeColumns = function() {
        var _this4 = this;
        var columnsController = this._columnsController;
        var visibleColumns = columnsController.getVisibleColumns();
        var columnAutoWidth = this.option("columnAutoWidth");
        var wordWrapEnabled = this.option("wordWrapEnabled");
        var hasUndefinedColumnWidth = visibleColumns.some((function(column) {
            return !(0, _type.isDefined)(column.width)
        }));
        var needBestFit = this._needBestFit();
        var hasMinWidth = false;
        var resetBestFitMode;
        var isColumnWidthsCorrected = false;
        var resultWidths = [];
        var focusedElement;
        var selectionRange;
        !needBestFit && (0, _iterator.each)(visibleColumns, (function(index, column) {
            if ("auto" === column.width) {
                needBestFit = true;
                return false
            }
            return
        }));
        (0, _iterator.each)(visibleColumns, (function(index, column) {
            if (column.minWidth) {
                hasMinWidth = true;
                return false
            }
            return
        }));
        this._setVisibleWidths(visibleColumns, []);
        var $element = this.component.$element();
        if (needBestFit) {
            focusedElement = _dom_adapter.default.getActiveElement($element.get(0));
            selectionRange = _m_utils.default.getSelectionRange(focusedElement);
            this._toggleBestFitMode(true);
            resetBestFitMode = true
        }
        this._toggleContentMinHeight(wordWrapEnabled);
        if ($element && $element.get(0) && this._maxWidth) {
            delete this._maxWidth;
            $element[0].style.maxWidth = ""
        }(0, _common.deferUpdate)((function() {
            if (needBestFit) {
                resultWidths = _this4._getBestFitWidths();
                (0, _iterator.each)(visibleColumns, (function(index, column) {
                    var columnId = columnsController.getColumnId(column);
                    columnsController.columnOption(columnId, "bestFitWidth", resultWidths[index], true)
                }))
            } else if (hasMinWidth) {
                resultWidths = _this4._getBestFitWidths()
            }(0, _iterator.each)(visibleColumns, (function(index) {
                var width = this.width;
                if ("auto" !== width) {
                    if ((0, _type.isDefined)(width)) {
                        resultWidths[index] = (0, _type.isNumeric)(width) || isPixelWidth(width) ? parseFloat(width) : width
                    } else if (!columnAutoWidth) {
                        resultWidths[index] = void 0
                    }
                }
            }));
            if (resetBestFitMode) {
                _this4._toggleBestFitMode(false);
                resetBestFitMode = false;
                if (focusedElement && focusedElement !== _dom_adapter.default.getActiveElement()) {
                    var isFocusOutsideWindow = (0, _position.getBoundingRect)(focusedElement).bottom < 0;
                    if (!isFocusOutsideWindow) {
                        restoreFocus(focusedElement, selectionRange)
                    }
                }
            }
            isColumnWidthsCorrected = _this4._correctColumnWidths(resultWidths, visibleColumns);
            if (columnAutoWidth) {
                ! function() {
                    var expandColumnWidth;
                    (0, _iterator.each)(visibleColumns, (function(index, column) {
                        if ("groupExpand" === column.type) {
                            expandColumnWidth = resultWidths[index]
                        }
                    }));
                    (0, _iterator.each)(visibleColumns, (function(index, column) {
                        if ("groupExpand" === column.type && expandColumnWidth) {
                            resultWidths[index] = expandColumnWidth
                        }
                    }))
                }();
                if (_this4._needStretch()) {
                    _this4._processStretch(resultWidths, visibleColumns)
                }
            }(0, _common.deferRender)((function() {
                if (needBestFit || isColumnWidthsCorrected || hasUndefinedColumnWidth) {
                    _this4._setVisibleWidths(visibleColumns, resultWidths)
                }
                if (wordWrapEnabled) {
                    _this4._toggleContentMinHeight(false)
                }
            }))
        }))
    };
    _proto._needBestFit = function() {
        return this.option("columnAutoWidth")
    };
    _proto._needStretch = function() {
        return this._columnsController.getVisibleColumns().some((function(c) {
            return "auto" === c.width && !c.command
        }))
    };
    _proto._getAverageColumnsWidth = function(resultWidths) {
        var freeWidth = calculateFreeWidth(this, resultWidths);
        var columnCountWithoutWidth = resultWidths.filter((function(width) {
            return void 0 === width
        })).length;
        return freeWidth / columnCountWithoutWidth
    };
    _proto._correctColumnWidths = function(resultWidths, visibleColumns) {
        var that = this;
        var i;
        var hasPercentWidth = false;
        var hasAutoWidth = false;
        var isColumnWidthsCorrected = false;
        var $element = that.component.$element();
        var hasWidth = that._hasWidth;
        var _loop = function() {
            var index = i;
            var column = visibleColumns[index];
            var isHiddenColumn = resultWidths[index] === HIDDEN_COLUMNS_WIDTH;
            var width = resultWidths[index];
            var minWidth = column.minWidth;
            if (minWidth) {
                if (void 0 === width) {
                    var averageColumnsWidth = that._getAverageColumnsWidth(resultWidths);
                    width = averageColumnsWidth
                } else if (isPercentWidth(width)) {
                    var freeWidth = calculateFreeWidthWithCurrentMinWidth(that, index, minWidth, resultWidths);
                    if (freeWidth < 0) {
                        width = -1
                    }
                }
            }
            var realColumnWidth = that._getRealColumnWidth(index, resultWidths.map((function(columnWidth, columnIndex) {
                return index === columnIndex ? width : columnWidth
            })));
            if (minWidth && !isHiddenColumn && realColumnWidth < minWidth) {
                resultWidths[index] = minWidth;
                isColumnWidthsCorrected = true;
                i = -1
            }
            if (!(0, _type.isDefined)(column.width)) {
                hasAutoWidth = true
            }
            if (isPercentWidth(column.width)) {
                hasPercentWidth = true
            }
        };
        for (i = 0; i < visibleColumns.length; i++) {
            _loop()
        }
        if (!hasAutoWidth && resultWidths.length) {
            var $rowsViewElement = that._rowsView.element();
            var contentWidth = that._rowsView.contentWidth();
            var scrollbarWidth = that._rowsView.getScrollbarWidth();
            var totalWidth = that._getTotalWidth(resultWidths, contentWidth);
            if (totalWidth < contentWidth) {
                var lastColumnIndex = _m_utils.default.getLastResizableColumnIndex(visibleColumns, resultWidths);
                if (lastColumnIndex >= 0) {
                    resultWidths[lastColumnIndex] = "auto";
                    isColumnWidthsCorrected = true;
                    if (false === hasWidth && !hasPercentWidth) {
                        var borderWidth = that.option("showBorders") ? Math.ceil((0, _size.getOuterWidth)($rowsViewElement) - (0, _size.getInnerWidth)($rowsViewElement)) : 0;
                        that._maxWidth = totalWidth + scrollbarWidth + borderWidth;
                        $element.css("maxWidth", that._maxWidth)
                    }
                }
            }
        }
        return isColumnWidthsCorrected
    };
    _proto._processStretch = function(resultSizes, visibleColumns) {
        var groupSize = this._rowsView.contentWidth();
        var tableSize = this._getTotalWidth(resultSizes, groupSize);
        var unusedIndexes = {
            length: 0
        };
        if (!resultSizes.length) {
            return
        }(0, _iterator.each)(visibleColumns, (function(index) {
            if (this.width || resultSizes[index] === HIDDEN_COLUMNS_WIDTH) {
                unusedIndexes[index] = true;
                unusedIndexes.length++
            }
        }));
        var diff = groupSize - tableSize;
        var diffElement = Math.floor(diff / (resultSizes.length - unusedIndexes.length));
        var onePixelElementsCount = diff - diffElement * (resultSizes.length - unusedIndexes.length);
        if (diff >= 0) {
            for (var i = 0; i < resultSizes.length; i++) {
                if (unusedIndexes[i]) {
                    continue
                }
                resultSizes[i] += diffElement;
                if (onePixelElementsCount > 0) {
                    if (onePixelElementsCount < 1) {
                        resultSizes[i] += onePixelElementsCount;
                        onePixelElementsCount = 0
                    } else {
                        resultSizes[i]++;
                        onePixelElementsCount--
                    }
                }
            }
        }
    };
    _proto._getRealColumnWidth = function(columnIndex, columnWidths, groupWidth) {
        var ratio = 1;
        var width = columnWidths[columnIndex];
        if (!isPercentWidth(width)) {
            return parseFloat(width)
        }
        var percentTotalWidth = columnWidths.reduce((function(sum, width, index) {
            if (!isPercentWidth(width)) {
                return sum
            }
            return sum + parseFloat(width)
        }), 0);
        var pixelTotalWidth = columnWidths.reduce((function(sum, width) {
            if (!width || width === HIDDEN_COLUMNS_WIDTH || isPercentWidth(width)) {
                return sum
            }
            return sum + parseFloat(width)
        }), 0);
        groupWidth = groupWidth || this._rowsView.contentWidth();
        var freeSpace = groupWidth - pixelTotalWidth;
        var percentTotalWidthInPixel = percentTotalWidth * groupWidth / 100;
        if (pixelTotalWidth > 0 && percentTotalWidthInPixel + pixelTotalWidth >= groupWidth) {
            ratio = percentTotalWidthInPixel > freeSpace ? freeSpace / percentTotalWidthInPixel : 1
        }
        return parseFloat(width) * groupWidth * ratio / 100
    };
    _proto._getTotalWidth = function(widths, groupWidth) {
        var result = 0;
        for (var i = 0; i < widths.length; i++) {
            var width = widths[i];
            if (width && width !== HIDDEN_COLUMNS_WIDTH) {
                result += this._getRealColumnWidth(i, widths, groupWidth)
            }
        }
        return Math.ceil(result)
    };
    _proto._getGroupElement = function() {
        return this.component.$element().children().get(0)
    };
    _proto.updateSize = function(rootElement) {
        var $rootElement = (0, _renderer.default)(rootElement);
        var importantMarginClass = this.addWidgetPrefix(IMPORTANT_MARGIN_CLASS);
        if (void 0 === this._hasHeight && $rootElement && $rootElement.is(":visible") && (0, _size.getWidth)($rootElement)) {
            var $groupElement = $rootElement.children(".".concat(this.getWidgetContainerClass()));
            if ($groupElement.length) {
                $groupElement.detach()
            }
            this._hasHeight = !!(0, _size.getHeight)($rootElement);
            var width = (0, _size.getWidth)($rootElement);
            $rootElement.addClass(importantMarginClass);
            this._hasWidth = (0, _size.getWidth)($rootElement) === width;
            $rootElement.removeClass(importantMarginClass);
            if ($groupElement.length) {
                $groupElement.appendTo($rootElement)
            }
        }
    };
    _proto.publicMethods = function() {
        return ["resize", "updateDimensions"]
    };
    _proto._waitAsyncTemplates = function() {
        var _a, _b, _c;
        return (0, _deferred.when)(null === (_a = this._columnHeadersView) || void 0 === _a ? void 0 : _a.waitAsyncTemplates(true), null === (_b = this._rowsView) || void 0 === _b ? void 0 : _b.waitAsyncTemplates(true), null === (_c = this._footerView) || void 0 === _c ? void 0 : _c.waitAsyncTemplates(true))
    };
    _proto.resize = function() {
        var _this5 = this;
        if (this.component._requireResize) {
            return
        }
        var d = new _deferred.Deferred;
        this._waitAsyncTemplates().done((function() {
            (0, _deferred.when)(_this5.updateDimensions()).done(d.resolve).fail(d.reject)
        })).fail(d.reject);
        return d.promise()
    };
    _proto.updateDimensions = function(checkSize) {
        var that = this;
        that._initPostRenderHandlers();
        if (!that._checkSize(checkSize)) {
            return
        }
        var prevResult = that._resizeDeferred;
        var result = that._resizeDeferred = new _deferred.Deferred;
        (0, _deferred.when)(prevResult).always((function() {
            (0, _common.deferRender)((function() {
                if (that._dataController.isLoaded()) {
                    that._synchronizeColumns()
                }
                that._resetGroupElementHeight();
                (0, _common.deferUpdate)((function() {
                    (0, _common.deferRender)((function() {
                        (0, _common.deferUpdate)((function() {
                            that._updateDimensionsCore()
                        }))
                    }))
                }))
            })).done(result.resolve).fail(result.reject)
        }));
        return result.promise()
    };
    _proto._resetGroupElementHeight = function() {
        var groupElement = this._getGroupElement();
        var scrollable = this._rowsView.getScrollable();
        if (groupElement && groupElement.style.height && (!scrollable || !scrollable.scrollTop())) {
            groupElement.style.height = ""
        }
    };
    _proto._checkSize = function(checkSize) {
        var $rootElement = this.component.$element();
        var isWidgetVisible = $rootElement.is(":visible");
        var isGridSizeChanged = this._lastWidth !== (0, _size.getWidth)($rootElement) || this._lastHeight !== (0, _size.getHeight)($rootElement) || this._devicePixelRatio !== (0, _window.getWindow)().devicePixelRatio;
        return isWidgetVisible && (!checkSize || isGridSizeChanged)
    };
    _proto._setScrollerSpacingCore = function() {
        var that = this;
        var vScrollbarWidth = that._rowsView.getScrollbarWidth();
        var hScrollbarWidth = that._rowsView.getScrollbarWidth(true);
        (0, _common.deferRender)((function() {
            that._columnHeadersView && that._columnHeadersView.setScrollerSpacing(vScrollbarWidth);
            that._footerView && that._footerView.setScrollerSpacing(vScrollbarWidth);
            that._rowsView.setScrollerSpacing(vScrollbarWidth, hScrollbarWidth)
        }))
    };
    _proto._setScrollerSpacing = function() {
        var _this6 = this;
        var scrollable = this._rowsView.getScrollable();
        var isNativeScrolling = true === this.option("scrolling.useNative");
        if (!scrollable || isNativeScrolling) {
            (0, _common.deferRender)((function() {
                (0, _common.deferUpdate)((function() {
                    _this6._setScrollerSpacingCore()
                }))
            }))
        } else {
            this._setScrollerSpacingCore()
        }
    };
    _proto._updateDimensionsCore = function() {
        var _a;
        var that = this;
        var dataController = that._dataController;
        var editorFactory = that.getController("editorFactory");
        var rowsView = that._rowsView;
        var $rootElement = that.component.$element();
        var groupElement = this._getGroupElement();
        var rootElementHeight = (0, _size.getHeight)($rootElement);
        var height = null !== (_a = that.option("height")) && void 0 !== _a ? _a : $rootElement.get(0).style.height;
        var isHeightSpecified = !!height && "auto" !== height;
        var maxHeight = parseInt($rootElement.css("maxHeight"));
        var maxHeightHappened = maxHeight && rootElementHeight >= maxHeight;
        var isMaxHeightApplied = groupElement && groupElement.scrollHeight === groupElement.offsetHeight;
        that.updateSize($rootElement);
        (0, _common.deferRender)((function() {
            var hasHeight = that._hasHeight || !!maxHeight || isHeightSpecified;
            rowsView.hasHeight(hasHeight);
            if (maxHeightHappened && !isMaxHeightApplied) {
                (0, _renderer.default)(groupElement).css("height", maxHeight)
            }
            if (!dataController.isLoaded()) {
                rowsView.setLoading(dataController.isLoading());
                return
            }(0, _common.deferUpdate)((function() {
                that._updateLastSizes($rootElement);
                that._setScrollerSpacing();
                (0, _iterator.each)(VIEW_NAMES, (function(index, viewName) {
                    var view = that.getView(viewName);
                    if (view) {
                        view.resize()
                    }
                }));
                editorFactory && editorFactory.resize()
            }))
        }))
    };
    _proto._updateLastSizes = function($rootElement) {
        this._lastWidth = (0, _size.getWidth)($rootElement);
        this._lastHeight = (0, _size.getHeight)($rootElement);
        this._devicePixelRatio = (0, _window.getWindow)().devicePixelRatio
    };
    _proto.optionChanged = function(args) {
        switch (args.name) {
            case "width":
            case "height":
                this.component._renderDimensions();
                this.resize();
            case "renderAsync":
                args.handled = true;
                return;
            default:
                _modules$ViewControll.prototype.optionChanged.call(this, args)
        }
    };
    _proto.init = function() {
        this._prevContentMinHeight = null;
        this._dataController = this.getController("data");
        this._columnsController = this.getController("columns");
        this._columnHeadersView = this.getView("columnHeadersView");
        this._footerView = this.getView("footerView");
        this._rowsView = this.getView("rowsView")
    };
    return ResizingController
}(_m_modules.default.ViewController);
exports.ResizingController = ResizingController;
var SynchronizeScrollingController = function(_modules$ViewControll2) {
    _inheritsLoose(SynchronizeScrollingController, _modules$ViewControll2);

    function SynchronizeScrollingController() {
        return _modules$ViewControll2.apply(this, arguments) || this
    }
    var _proto2 = SynchronizeScrollingController.prototype;
    _proto2._scrollChangedHandler = function(views, pos, viewName) {
        for (var j = 0; j < views.length; j++) {
            if (views[j] && views[j].name !== viewName) {
                views[j].scrollTo({
                    left: pos.left,
                    top: pos.top
                })
            }
        }
    };
    _proto2.init = function() {
        var views = [this.getView("columnHeadersView"), this.getView("footerView"), this.getView("rowsView")];
        for (var i = 0; i < views.length; i++) {
            var view = views[i];
            if (view) {
                view.scrollChanged.add(this._scrollChangedHandler.bind(this, views))
            }
        }
    };
    return SynchronizeScrollingController
}(_m_modules.default.ViewController);
var GridView = function(_modules$View) {
    _inheritsLoose(GridView, _modules$View);

    function GridView() {
        return _modules$View.apply(this, arguments) || this
    }
    var _proto3 = GridView.prototype;
    _proto3._endUpdateCore = function() {
        if (this.component._requireResize) {
            this.component._requireResize = false;
            this._resizingController.resize()
        }
    };
    _proto3.init = function() {
        this._resizingController = this.getController("resizing");
        this._dataController = this.getController("data")
    };
    _proto3.getView = function(name) {
        return this.component._views[name]
    };
    _proto3.element = function() {
        return this._groupElement
    };
    _proto3.optionChanged = function(args) {
        if ((0, _type.isDefined)(this._groupElement) && "showBorders" === args.name) {
            this._groupElement.toggleClass(this.addWidgetPrefix(BORDERS_CLASS), !!args.value);
            args.handled = true
        } else {
            _modules$View.prototype.optionChanged.call(this, args)
        }
    };
    _proto3._renderViews = function($groupElement) {
        var that = this;
        (0, _iterator.each)(VIEW_NAMES, (function(index, viewName) {
            var view = that.getView(viewName);
            if (view) {
                view.render($groupElement)
            }
        }))
    };
    _proto3._getTableRoleName = function() {
        return "group"
    };
    _proto3.render = function($rootElement) {
        var isFirstRender = !this._groupElement;
        var $groupElement = this._groupElement || (0, _renderer.default)("<div>").addClass(this.getWidgetContainerClass());
        $groupElement.addClass(GRIDBASE_CONTAINER_CLASS);
        $groupElement.toggleClass(this.addWidgetPrefix(BORDERS_CLASS), !!this.option("showBorders"));
        this.setAria("role", "presentation", $rootElement);
        this.component.setAria("role", this._getTableRoleName(), $groupElement);
        this._rootElement = $rootElement || this._rootElement;
        if (isFirstRender) {
            this._groupElement = $groupElement;
            (0, _window.hasWindow)() && this.getController("resizing").updateSize($rootElement);
            $groupElement.appendTo($rootElement)
        }
        this._renderViews($groupElement)
    };
    _proto3.update = function() {
        var $rootElement = this._rootElement;
        var $groupElement = this._groupElement;
        var resizingController = this.getController("resizing");
        if ($rootElement && $groupElement) {
            resizingController.resize();
            if (this._dataController.isLoaded()) {
                this._resizingController.fireContentReadyAction()
            }
        }
    };
    return GridView
}(_m_modules.default.View);
var gridViewModule = {
    defaultOptions: function() {
        return {
            showBorders: false,
            renderAsync: false
        }
    },
    controllers: {
        resizing: ResizingController,
        synchronizeScrolling: SynchronizeScrollingController
    },
    views: {
        gridView: GridView
    },
    VIEW_NAMES: VIEW_NAMES
};
exports.gridViewModule = gridViewModule;
