var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
import ActionTypes from './PaginationActionTypes';
export var initialState = {
    filterMap: {},
    skip: 0,
    sortBy: null,
    sortOrder: null,
    take: 10,
    total: Number.POSITIVE_INFINITY,
};
var getStateDiff = function (state, _a) {
    var _b = _a === void 0 ? {} : _a, type = _b.type, payload = _b.payload;
    switch (type) {
        case ActionTypes.RESET_PAGING:
            return {
                // Don't reset sort or filters
                skip: initialState.skip,
                take: initialState.take,
                total: initialState.total,
            };
        case ActionTypes.SET_FILTER_MAP:
            return {
                filterMap: payload.filterMap,
            };
        case ActionTypes.SET_SKIP:
            return {
                skip: payload.skip,
            };
        case ActionTypes.SET_SORT:
            return {
                sortBy: payload.sortBy,
                sortOrder: payload.sortOrder,
            };
        case ActionTypes.SET_TAKE:
            return {
                take: payload.take,
            };
        case ActionTypes.SET_TOTAL:
            return {
                total: payload.total,
            };
        default:
            return null;
    }
};
export default (function (state, action) {
    if (state === void 0) { state = initialState; }
    var stateDiff = getStateDiff(state, action);
    if (stateDiff) {
        return __assign(__assign({}, state), stateDiff);
    }
    return state;
});
//# sourceMappingURL=PaginationReducer.js.map