var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __read = (this && this.__read) || function (o, n) {
    var m = typeof Symbol === "function" && o[Symbol.iterator];
    if (!m) return o;
    var i = m.call(o), r, ar = [], e;
    try {
        while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
    }
    catch (error) { e = { error: error }; }
    finally {
        try {
            if (r && !r.done && (m = i["return"])) m.call(i);
        }
        finally { if (e) throw e.error; }
    }
    return ar;
};
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
    if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
        if (ar || !(i in from)) {
            if (!ar) ar = Array.prototype.slice.call(from, 0, i);
            ar[i] = from[i];
        }
    }
    return to.concat(ar || Array.prototype.slice.call(from));
};
import { valueConverter } from "aurelia-framework";
export var SplitValueConverter = (function () {
    function SplitValueConverter() {
    }
    SplitValueConverter.prototype.toView = function (object, char) {
        if (char === void 0) { char = ","; }
        return (object || "").split(new RegExp("[".concat(char, "]")));
    };
    SplitValueConverter = __decorate([
        valueConverter("split")
    ], SplitValueConverter);
    return SplitValueConverter;
}());
export var ObjectMapValueConverter = (function () {
    function ObjectMapValueConverter() {
    }
    ObjectMapValueConverter.prototype.toView = function (object) {
        if (isEmpty(object)) {
            return new Map();
        }
        var map = new Map();
        object.forEach(function (value, key) { return map.set(key, value); });
        return map;
    };
    ObjectMapValueConverter = __decorate([
        valueConverter("objectMap")
    ], ObjectMapValueConverter);
    return ObjectMapValueConverter;
}());
export var GroupValueConverter = (function () {
    function GroupValueConverter() {
    }
    GroupValueConverter.prototype.toView = function (array, property) {
        return array.groupBy(property);
    };
    GroupValueConverter = __decorate([
        valueConverter("group")
    ], GroupValueConverter);
    return GroupValueConverter;
}());
export var SliceValueConverter = (function () {
    function SliceValueConverter() {
    }
    SliceValueConverter.prototype.toView = function (array, end) {
        if (end === void 0) { end = 0; }
        return end === 0 ? array : array.slice(0, end);
    };
    SliceValueConverter = __decorate([
        valueConverter("slice")
    ], SliceValueConverter);
    return SliceValueConverter;
}());
export var FilterValueConverter = (function () {
    function FilterValueConverter() {
    }
    FilterValueConverter.prototype.toView = function (array, value, property) {
        if (isEmpty(array)) {
            return [];
        }
        if (array instanceof Map) {
            var map_1 = new Map();
            array.forEach(function (v, k) {
                k.toString() == value ||
                    (property
                        ? v[property].toString() == value.toString()
                        : v.toString() == value.toString())
                    ? map_1.set(k, v)
                    : fn();
            });
            return map_1;
        }
        else {
            var filtered = array.filter(function (o) {
                var _a;
                return property
                    ? (o[property] == null ? value == null || value === '' : ((_a = o[property]) === null || _a === void 0 ? void 0 : _a.toString()) == (value === null || value === void 0 ? void 0 : value.toString()))
                    : (o == null ? value == null || value === '' : (o === null || o === void 0 ? void 0 : o.toString()) == (value === null || value === void 0 ? void 0 : value.toString()));
            });
            return filtered;
        }
    };
    FilterValueConverter = __decorate([
        valueConverter("filter")
    ], FilterValueConverter);
    return FilterValueConverter;
}());
export var SearchValueConverter = (function () {
    function SearchValueConverter() {
    }
    SearchValueConverter.prototype.toView = function (array, value, property) {
        if (isEmpty(array)) {
            return [];
        }
        else if ((value || '').length == 0) {
            return array;
        }
        if (array instanceof Map) {
            var map_2 = new Map();
            array.forEach(function (v, k) {
                k.toString().toLocaleLowerCase().includes(value) ||
                    (property
                        ? v[property].toString().toLocaleLowerCase().includes(value.toString().toLocaleLowerCase())
                        : v.toString().toLocaleLowerCase().includes(value.toString().toLocaleLowerCase()))
                    ? map_2.set(k, v)
                    : fn();
            });
            return map_2;
        }
        else {
            var filtered = array.filter(function (o) {
                return property
                    ? o[property].toString().toLocaleLowerCase().includes(value.toString().toLocaleLowerCase())
                    : o.toString().toLocaleLowerCase().includes(value.toString().toLocaleLowerCase());
            });
            return filtered;
        }
    };
    SearchValueConverter = __decorate([
        valueConverter("search")
    ], SearchValueConverter);
    return SearchValueConverter;
}());
export var OrderByValueConverter = (function () {
    function OrderByValueConverter() {
    }
    OrderByValueConverter.prototype.toView = function (array, property, isAscending) {
        if (isAscending === void 0) { isAscending = true; }
        if (isEmpty(array)) {
            return [];
        }
        var up = 1;
        var down = -1;
        if (!isAscending) {
            up = -1;
            down = 1;
        }
        if (array instanceof Map) {
            return new Map(__spreadArray([], __read(array), false).sort(function (a, b) { return (a[0] > b[0] ? up : down); }));
        }
        return __spreadArray([], __read(array), false).sort(function (a, b) { return (a[property] > b[property] ? up : down); });
    };
    OrderByValueConverter = __decorate([
        valueConverter("orderBy")
    ], OrderByValueConverter);
    return OrderByValueConverter;
}());
export var SortValueConverter = (function () {
    function SortValueConverter() {
    }
    SortValueConverter.prototype.toView = function (array, property, isAscending, enabled) {
        if (isAscending === void 0) { isAscending = true; }
        if (enabled === void 0) { enabled = true; }
        if (!enabled || isEmpty(array)) {
            return array;
        }
        if (array instanceof Map) {
            return new Map(__spreadArray([], __read(array), false).sortBy("0", isAscending));
        }
        return __spreadArray([], __read(array), false).sortBy(property, isAscending);
    };
    SortValueConverter = __decorate([
        valueConverter("sort")
    ], SortValueConverter);
    return SortValueConverter;
}());
export var FilterFnConverter = (function () {
    function FilterFnConverter() {
    }
    FilterFnConverter.prototype.toView = function (array, filterFn) {
        if (isEmpty(array)) {
            return [];
        }
        if (array instanceof Map) {
            var map_3 = new Map();
            array.forEach(function (v, k) { return filterFn(v, k) ? map_3.set(k, v) : fn(); });
            return map_3;
        }
        else {
            return array.filter(filterFn);
        }
    };
    FilterFnConverter = __decorate([
        valueConverter("filterFn")
    ], FilterFnConverter);
    return FilterFnConverter;
}());
export var ArrayLengthConverter = (function () {
    function ArrayLengthConverter() {
    }
    ArrayLengthConverter.prototype.toView = function (array) {
        return (array || []).length;
    };
    ArrayLengthConverter = __decorate([
        valueConverter('arrayLength')
    ], ArrayLengthConverter);
    return ArrayLengthConverter;
}());

//# sourceMappingURL=ui-object.js.map
