/**
 * DevExtreme (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/
 */
"use strict";
exports.SetPageSize = exports.SetPageIndex = exports.SetLoadPageCount = exports.PagingEnabled = exports.PageSize = exports.PageIndex = exports.PageCount = exports.LoadPageCount = exports.ApplyPagingToVisibleItems = exports.AddPagingToLocalDataState = exports.AddPagingToLoadOptions = void 0;
var _context = require("../../../../utils/plugin/context");
var _plugins = require("../plugins");

function _extends() {
    _extends = Object.assign ? Object.assign.bind() : function(target) {
        for (var i = 1; i < arguments.length; i++) {
            var source = arguments[i];
            for (var key in source) {
                if (Object.prototype.hasOwnProperty.call(source, key)) {
                    target[key] = source[key]
                }
            }
        }
        return target
    };
    return _extends.apply(this, arguments)
}
var PageIndex = (0, _context.createValue)();
exports.PageIndex = PageIndex;
var SetPageIndex = (0, _context.createValue)();
exports.SetPageIndex = SetPageIndex;
var PageSize = (0, _context.createValue)();
exports.PageSize = PageSize;
var SetPageSize = (0, _context.createValue)();
exports.SetPageSize = SetPageSize;
var PagingEnabled = (0, _context.createValue)();
exports.PagingEnabled = PagingEnabled;
var LoadPageCount = (0, _context.createValue)();
exports.LoadPageCount = LoadPageCount;
var SetLoadPageCount = (0, _context.createValue)();
exports.SetLoadPageCount = SetLoadPageCount;
var PageCount = (0, _context.createSelector)([_plugins.TotalCount, PageSize], (function(totalCount, pageSize) {
    if ("all" === pageSize) {
        return 1
    }
    return Math.ceil(totalCount / pageSize)
}));
exports.PageCount = PageCount;
var ApplyPagingToVisibleItems = (0, _context.createSelector)([_plugins.LocalVisibleItems, PagingEnabled, PageIndex, PageSize, LoadPageCount], (function(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)
}));
exports.ApplyPagingToVisibleItems = ApplyPagingToVisibleItems;
var AddPagingToLoadOptions = (0, _context.createSelector)([_plugins.LoadOptionsValue, PagingEnabled, PageIndex, PageSize, LoadPageCount, _plugins.RemoteOperations], (function(loadOptionsValue, pagingEnabled, pageIndex, pageSize, loadPageCount, remoteOperations) {
    if (!pagingEnabled || "all" === pageSize || !remoteOperations) {
        return loadOptionsValue
    }
    return _extends({}, loadOptionsValue, {
        skip: pageIndex * pageSize,
        take: pageSize * loadPageCount,
        requireTotalCount: true
    })
}));
exports.AddPagingToLoadOptions = AddPagingToLoadOptions;
var AddPagingToLocalDataState = (0, _context.createSelector)([_plugins.LocalDataState, PageIndex, PageSize], (function(localState, pageIndex, pageSize) {
    var state = void 0 !== localState ? _extends({}, localState, {
        dataOffset: pageIndex * pageSize
    }) : void 0;
    return state
}));
exports.AddPagingToLocalDataState = AddPagingToLocalDataState;
