"use strict";
var __extends = (this && this.__extends) || function (d, b) {
    for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
    function __() { this.constructor = d; }
    d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var _ = require("lodash");
var asyncDataSource_service_1 = require("../asyncDataSource.service");
var sort_1 = require("../../sorts/sort");
var ServerSideDataSource = (function (_super) {
    __extends(ServerSideDataSource, _super);
    function ServerSideDataSource(getDataSet, dataSourceProcessor, array, object) {
        var _this = _super.call(this, getDataSet, dataSourceProcessor, array) || this;
        _this.object = object;
        return _this;
    }
    ServerSideDataSource.prototype.refresh = function () {
        this.reload();
    };
    ServerSideDataSource.prototype.getParams = function () {
        var filterDictionary = this.array.toDictionary(this.filters, function (filter) {
            return filter.type;
        });
        return {
            filters: _.mapValues(filterDictionary, function (filter) {
                if (_.isFunction(filter.serialize)) {
                    return filter.serialize();
                }
                return null;
            }),
            sorts: _.map(this.sorts, function (sort) {
                return {
                    column: sort.column.label,
                    direction: sort_1.SortDirection.getFullName(sort.direction),
                };
            }),
            paging: {
                pageNumber: this.pager.pageNumber,
                pageSize: this.pager.pageSize,
            },
        };
    };
    ServerSideDataSource.prototype.resolveReload = function (result) {
        var data = result;
        _super.prototype.resolveReload.call(this, data.dataSet);
        this.setProcessedData({
            count: data.count,
            filteredDataSet: data.dataSet,
            dataSet: data.dataSet,
        });
        this.redrawing.next(null);
    };
    return ServerSideDataSource;
}(asyncDataSource_service_1.AsyncDataSource));
exports.ServerSideDataSource = ServerSideDataSource;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2VydmVyU2lkZURhdGFTb3VyY2Uuc2VydmljZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInNlcnZlclNpZGVEYXRhU291cmNlLnNlcnZpY2UudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7O0FBQUEsMEJBQTRCO0FBTzVCLHNFQUFpRztBQUV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