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;
};
import { valueConverter } from "aurelia-framework";
import { parsePhoneNumberFromString } from "libphonenumber-js";
import { UIFormat } from "../utils/ui-format";
var getPhone = function (value, country) {
    if (value === void 0) { value = ""; }
    if (country === void 0) { country = "us"; }
    var number = parsePhoneNumberFromString(value || "", country);
    return number ? number : {
        country: "",
        formatNational: function () { return ""; },
        formatInternational: function () { return ""; }
    };
};
export var JsonValueConverter = (function () {
    function JsonValueConverter() {
    }
    JsonValueConverter.prototype.toView = function (value) {
        return JSON.stringify(value);
    };
    JsonValueConverter = __decorate([
        valueConverter("json")
    ], JsonValueConverter);
    return JsonValueConverter;
}());
export var PhoneValueConverter = (function () {
    function PhoneValueConverter() {
    }
    PhoneValueConverter.prototype.toView = function (value, country) {
        if (country === void 0) { country = ""; }
        return getPhone(value, country).formatInternational();
    };
    PhoneValueConverter = __decorate([
        valueConverter("phone")
    ], PhoneValueConverter);
    return PhoneValueConverter;
}());
export var PhoneLocalValueConverter = (function () {
    function PhoneLocalValueConverter() {
    }
    PhoneLocalValueConverter.prototype.toView = function (value, country) {
        if (country === void 0) { country = "us"; }
        return getPhone(value, country).formatNational();
    };
    PhoneLocalValueConverter = __decorate([
        valueConverter("phoneLocal")
    ], PhoneLocalValueConverter);
    return PhoneLocalValueConverter;
}());
export var PhoneHtmlValueConverter = (function () {
    function PhoneHtmlValueConverter() {
    }
    PhoneHtmlValueConverter.prototype.toView = function (value, country) {
        if (country === void 0) { country = ""; }
        var phoneNumber = getPhone(value, country);
        return "<span class=\"ui-flag ".concat(phoneNumber.country, "\"></span>&nbsp;").concat(phoneNumber.formatInternational());
    };
    PhoneHtmlValueConverter = __decorate([
        valueConverter("phoneHtml")
    ], PhoneHtmlValueConverter);
    return PhoneHtmlValueConverter;
}());
export var PhoneLocalHtmlValueConverter = (function () {
    function PhoneLocalHtmlValueConverter() {
    }
    PhoneLocalHtmlValueConverter.prototype.toView = function (value, country) {
        if (country === void 0) { country = "us"; }
        var phoneNumber = getPhone(value, country);
        return "<span class=\"ui-flag ".concat(phoneNumber.country, "\"></span>&nbsp;").concat(phoneNumber.formatNational());
    };
    PhoneLocalHtmlValueConverter = __decorate([
        valueConverter("phoneLocalHtml")
    ], PhoneLocalHtmlValueConverter);
    return PhoneLocalHtmlValueConverter;
}());
export var DateValueConverter = (function () {
    function DateValueConverter() {
    }
    DateValueConverter.prototype.toView = function (value, format) {
        return UIFormat.date(value, format);
    };
    DateValueConverter = __decorate([
        valueConverter("date")
    ], DateValueConverter);
    return DateValueConverter;
}());
export var TimeValueConverter = (function () {
    function TimeValueConverter() {
    }
    TimeValueConverter.prototype.toView = function (value, format) {
        return UIFormat.time(value, format);
    };
    TimeValueConverter = __decorate([
        valueConverter("time")
    ], TimeValueConverter);
    return TimeValueConverter;
}());
export var DatetimeValueConverter = (function () {
    function DatetimeValueConverter() {
    }
    DatetimeValueConverter.prototype.toView = function (value, format) {
        return UIFormat.datetime(value, format);
    };
    DatetimeValueConverter = __decorate([
        valueConverter("datetime")
    ], DatetimeValueConverter);
    return DatetimeValueConverter;
}());
export var FromNowValueConverter = (function () {
    function FromNowValueConverter() {
    }
    FromNowValueConverter.prototype.toView = function (value) {
        return UIFormat.fromNow(value);
    };
    FromNowValueConverter = __decorate([
        valueConverter("fromnow")
    ], FromNowValueConverter);
    return FromNowValueConverter;
}());
export var AgeValueConverter = (function () {
    function AgeValueConverter() {
    }
    AgeValueConverter.prototype.toView = function (value) {
        return UIFormat.age(value);
    };
    AgeValueConverter = __decorate([
        valueConverter("age")
    ], AgeValueConverter);
    return AgeValueConverter;
}());
export var UtcValueConverter = (function () {
    function UtcValueConverter() {
    }
    UtcValueConverter.prototype.toView = function (value) {
        return UIFormat.utcDate(value);
    };
    UtcValueConverter = __decorate([
        valueConverter("utc")
    ], UtcValueConverter);
    return UtcValueConverter;
}());
export var IsoValueConverter = (function () {
    function IsoValueConverter() {
    }
    IsoValueConverter.prototype.toView = function (value) {
        return UIFormat.dateToISO(value);
    };
    IsoValueConverter = __decorate([
        valueConverter("iso")
    ], IsoValueConverter);
    return IsoValueConverter;
}());
export var NumberValueConverter = (function () {
    function NumberValueConverter() {
    }
    NumberValueConverter.prototype.toView = function (value, format) {
        return UIFormat.number(value, format);
    };
    NumberValueConverter = __decorate([
        valueConverter("number")
    ], NumberValueConverter);
    return NumberValueConverter;
}());
export var PercentValueConverter = (function () {
    function PercentValueConverter() {
    }
    PercentValueConverter.prototype.toView = function (value) {
        return UIFormat.percent(value);
    };
    PercentValueConverter = __decorate([
        valueConverter("percent")
    ], PercentValueConverter);
    return PercentValueConverter;
}());
export var EuroValueConverter = (function () {
    function EuroValueConverter() {
    }
    EuroValueConverter.prototype.toView = function (value) {
        return UIFormat.euro(value);
    };
    EuroValueConverter = __decorate([
        valueConverter("euro")
    ], EuroValueConverter);
    return EuroValueConverter;
}());
export var DecimalValueConverter = (function () {
    function DecimalValueConverter() {
    }
    DecimalValueConverter.prototype.fromView = function (val) {
        var src = val.trim();
        if (src === "")
            return null;
        var fVal = parseFloat(src);
        if (isNaN(fVal) || fVal.toString() != val) {
            this.viewVal = val;
        }
        else {
            this.viewVal = null;
        }
        return val;
    };
    DecimalValueConverter.prototype.toView = function (value, format) {
        if (this.viewVal != null)
            return this.viewVal;
        return value;
    };
    DecimalValueConverter = __decorate([
        valueConverter("decimal")
    ], DecimalValueConverter);
    return DecimalValueConverter;
}());
export var BoolValueConverter = (function () {
    function BoolValueConverter() {
    }
    BoolValueConverter.prototype.toView = function (value) {
        if (value != null) {
            return (value) ? "\u2713" : "\u2716";
        }
        return null;
    };
    BoolValueConverter = __decorate([
        valueConverter("bool")
    ], BoolValueConverter);
    return BoolValueConverter;
}());
export var CurrencyValueConverter = (function () {
    function CurrencyValueConverter() {
    }
    CurrencyValueConverter.prototype.toView = function (value) {
        if (value != null) {
            return value.toLocaleString('de-DE', {
                minimumFractionDigits: 2,
                maximumFractionDigits: 2
            }) + ' €';
        }
        else {
            return '';
        }
    };
    CurrencyValueConverter = __decorate([
        valueConverter("currency")
    ], CurrencyValueConverter);
    return CurrencyValueConverter;
}());
export var IbanValueConverter = (function () {
    function IbanValueConverter() {
        this.NON_ALPHANUM = /[^a-zA-Z0-9]/g;
        this.EVERY_FOUR_CHARS = /(.{4})(?!$)/g;
    }
    IbanValueConverter.prototype.toView = function (value, separator) {
        if (separator === void 0) { separator = ' '; }
        if (value != null) {
            value = value.replace(this.NON_ALPHANUM, '').toUpperCase();
            return value.replace(this.EVERY_FOUR_CHARS, "$1" + separator);
        }
        else {
            return '';
        }
    };
    IbanValueConverter = __decorate([
        valueConverter("iban")
    ], IbanValueConverter);
    return IbanValueConverter;
}());
export var VCSValueConverter = (function () {
    function VCSValueConverter() {
        this.NON_ALPHANUM = /[^a-zA-Z0-9]/g;
        this.EVERY_FOUR_CHARS = /(.{4})(?!$)/g;
    }
    VCSValueConverter.prototype.toView = function (value, isVCS) {
        if (isVCS === void 0) { isVCS = true; }
        if (value == null || value.length != 12 || isVCS === false)
            return value;
        value = value.replace(this.NON_ALPHANUM, '').toUpperCase();
        if (value != null) {
            return "+++".concat(value.substring(0, 3), "/").concat(value.substring(3, 7), "/").concat(value.substring(7), "+++");
        }
        else {
            return '';
        }
    };
    VCSValueConverter = __decorate([
        valueConverter("vcs")
    ], VCSValueConverter);
    return VCSValueConverter;
}());
export var FileSizeValueConverter = (function () {
    function FileSizeValueConverter() {
    }
    FileSizeValueConverter.prototype.toView = function (value) {
        if (value && typeof (value) == 'number') {
            var formatedValue;
            var suffix;
            if (value > Math.pow(1024, 3)) {
                formatedValue = value / Math.pow(1024, 3);
                suffix = ' GB';
            }
            else if (value > Math.pow(1024, 2)) {
                formatedValue = value / Math.pow(1024, 2);
                suffix = ' MB';
            }
            else if (value > 1024) {
                formatedValue = value / 1024;
                suffix = ' KB';
            }
            else {
                formatedValue = value;
                suffix = ' B';
            }
            return formatedValue.toFixed(0) + suffix;
        }
        else {
            return '';
        }
    };
    FileSizeValueConverter = __decorate([
        valueConverter("fileSize")
    ], FileSizeValueConverter);
    return FileSizeValueConverter;
}());

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