/**
 * DevExtreme (bundles/__internal/grids/tree_list/m_virtual_scrolling.js)
 * Version: 23.2.4 (build 24056-0112)
 * Build date: Sun Feb 25 2024
 *
 * Copyright (c) 2012 - 2024 Developer Express Inc. ALL RIGHTS RESERVED
 * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
 */
"use strict";
var _extend = require("../../../core/utils/extend");
var _m_virtual_scrolling = require("../../grids/grid_core/virtual_scrolling/m_virtual_scrolling");
var _m_data_source_adapter = _interopRequireDefault(require("./data_source_adapter/m_data_source_adapter"));
var _m_core = _interopRequireDefault(require("./m_core"));

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)
}
const oldDefaultOptions = _m_virtual_scrolling.virtualScrollingModule.defaultOptions;
const originalDataControllerExtender = _m_virtual_scrolling.virtualScrollingModule.extenders.controllers.data;
_m_virtual_scrolling.virtualScrollingModule.extenders.controllers.data = (0, _extend.extend)({}, originalDataControllerExtender, {
    _loadOnOptionChange() {
        const virtualScrollController = this._dataSource && this._dataSource._virtualScrollController;
        virtualScrollController && virtualScrollController.reset();
        this.callBase()
    }
});
const dataSourceAdapterExtender = Base => function(_virtualScrollingData) {
    _inheritsLoose(VirtualScrollingDataSourceAdapterExtender, _virtualScrollingData);

    function VirtualScrollingDataSourceAdapterExtender() {
        return _virtualScrollingData.apply(this, arguments) || this
    }
    var _proto = VirtualScrollingDataSourceAdapterExtender.prototype;
    _proto.changeRowExpand = function() {
        return _virtualScrollingData.prototype.changeRowExpand.apply(this, arguments).done(() => {
            const viewportItemIndex = this.getViewportItemIndex();
            viewportItemIndex >= 0 && this.setViewportItemIndex(viewportItemIndex)
        })
    };
    return VirtualScrollingDataSourceAdapterExtender
}((0, _m_virtual_scrolling.dataSourceAdapterExtender)(Base));
_m_core.default.registerModule("virtualScrolling", (0, _extend.extend)({}, _m_virtual_scrolling.virtualScrollingModule, {
    defaultOptions: () => (0, _extend.extend)(true, oldDefaultOptions(), {
        scrolling: {
            mode: "virtual"
        }
    })
}));
_m_data_source_adapter.default.extend(dataSourceAdapterExtender);
