/**
 * DevExtreme (esm/renovation/ui/grids/data_grid_next/paging/plugins.js)
 * Version: 22.1.3 (build 22180-0310)
 * Build date: Wed Jun 29 2022
 *
 * Copyright (c) 2012 - 2022 Developer Express Inc. ALL RIGHTS RESERVED
 * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
 */
import _extends from "@babel/runtime/helpers/esm/extends";
import {
    createValue,
    createSelector
} from "../../../../utils/plugin/context";
import {
    TotalCount,
    LocalVisibleItems,
    LoadOptionsValue,
    RemoteOperations,
    LocalDataState
} from "../plugins";
export var PageIndex = createValue();
export var SetPageIndex = createValue();
export var PageSize = createValue();
export var SetPageSize = createValue();
export var PagingEnabled = createValue();
export var LoadPageCount = createValue();
export var SetLoadPageCount = createValue();
export var PageCount = createSelector([TotalCount, PageSize], (totalCount, pageSize) => {
    if ("all" === pageSize) {
        return 1
    }
    return Math.ceil(totalCount / pageSize)
});
export var ApplyPagingToVisibleItems = createSelector([LocalVisibleItems, PagingEnabled, PageIndex, PageSize, LoadPageCount], (visibleItems, pagingEnabled, pageIndex, pageSize, loadPageCount) => {
    if (!pagingEnabled || "all" === pageSize || void 0 === visibleItems) {
        return visibleItems
    }
    var start = pageIndex * pageSize;
    var end = start + pageSize * loadPageCount;
    return visibleItems.slice(start, end)
});
export var AddPagingToLoadOptions = createSelector([LoadOptionsValue, PagingEnabled, PageIndex, PageSize, LoadPageCount, RemoteOperations], (loadOptionsValue, pagingEnabled, pageIndex, pageSize, loadPageCount, remoteOperations) => {
    if (!pagingEnabled || "all" === pageSize || !remoteOperations) {
        return loadOptionsValue
    }
    return _extends({}, loadOptionsValue, {
        skip: pageIndex * pageSize,
        take: pageSize * loadPageCount,
        requireTotalCount: true
    })
});
export var AddPagingToLocalDataState = createSelector([LocalDataState, PageIndex, PageSize], (localState, pageIndex, pageSize) => {
    var state = void 0 !== localState ? _extends({}, localState, {
        dataOffset: pageIndex * pageSize
    }) : void 0;
    return state
});
