/**
 * DevExtreme (esm/__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/
 */
import {
    extend
} from "../../../core/utils/extend";
import {
    dataSourceAdapterExtender as virtualScrollingDataSourceAdapterExtender,
    virtualScrollingModule
} from "../../grids/grid_core/virtual_scrolling/m_virtual_scrolling";
import dataSourceAdapterProvider from "./data_source_adapter/m_data_source_adapter";
import gridCore from "./m_core";
var oldDefaultOptions = virtualScrollingModule.defaultOptions;
var originalDataControllerExtender = virtualScrollingModule.extenders.controllers.data;
virtualScrollingModule.extenders.controllers.data = extend({}, originalDataControllerExtender, {
    _loadOnOptionChange() {
        var virtualScrollController = this._dataSource && this._dataSource._virtualScrollController;
        virtualScrollController && virtualScrollController.reset();
        this.callBase()
    }
});
var dataSourceAdapterExtender = Base => class extends(virtualScrollingDataSourceAdapterExtender(Base)) {
    changeRowExpand() {
        return super.changeRowExpand.apply(this, arguments).done(() => {
            var viewportItemIndex = this.getViewportItemIndex();
            viewportItemIndex >= 0 && this.setViewportItemIndex(viewportItemIndex)
        })
    }
};
gridCore.registerModule("virtualScrolling", extend({}, virtualScrollingModule, {
    defaultOptions: () => extend(true, oldDefaultOptions(), {
        scrolling: {
            mode: "virtual"
        }
    })
}));
dataSourceAdapterProvider.extend(dataSourceAdapterExtender);
