"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.UIFormat = void 0;
var date_fns_1 = require("date-fns");
var moment_1 = __importDefault(require("moment"));
var numeral_1 = __importDefault(require("numeral"));
var UIFormat;
(function (UIFormat) {
    function parseDate(dt) {
        return typeof dt === "string" ? (0, date_fns_1.parseISO)(dt) : dt;
    }
    UIFormat.parseDate = parseDate;
    function date(dt, ft) {
        if (ft === void 0) { ft = "DD/MM/yyyy"; }
        dt = parseDate(dt);
        return !dt || !(0, date_fns_1.isValid)(dt)
            ? null
            : (0, moment_1.default)(dt).format(ft);
    }
    UIFormat.date = date;
    function time(dt, ft) {
        if (ft === void 0) { ft = "HH:mm"; }
        dt = parseDate(dt);
        return !dt || !(0, date_fns_1.isValid)(dt)
            ? null
            : (0, moment_1.default)(dt).format(ft);
    }
    UIFormat.time = time;
    function datetime(dt, ft) {
        if (ft === void 0) { ft = "DD MMM yyyy HH:mm"; }
        dt = parseDate(dt);
        return !dt || !(0, date_fns_1.isValid)(dt)
            ? null
            : (0, moment_1.default)(dt).format(ft);
    }
    UIFormat.datetime = datetime;
    function utcDate(dt) {
        dt = parseDate(dt);
        return !dt || !(0, date_fns_1.isValid)(dt) ? null : (0, date_fns_1.toDate)(dt).toISOString();
    }
    UIFormat.utcDate = utcDate;
    function dateToISO(dt) {
        dt = parseDate(dt);
        return !dt || !(0, date_fns_1.isValid)(dt)
            ? null
            : (0, moment_1.default)(dt).format("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
    }
    UIFormat.dateToISO = dateToISO;
    function age(dt) {
        dt = parseDate(dt);
        return !dt || !(0, date_fns_1.isValid)(dt) ? "" : (0, date_fns_1.formatDistanceStrict)(dt, new Date());
    }
    UIFormat.age = age;
    function fromNow(dt) {
        dt = parseDate(dt);
        return !dt || !(0, date_fns_1.isValid)(dt) ? "" : (0, date_fns_1.formatDistance)(dt, new Date(), { addSuffix: true });
    }
    UIFormat.fromNow = fromNow;
    function number(nm, fm) {
        if (fm === void 0) { fm = "0,0[.]00"; }
        return nm === null || isNaN(nm) ? "" : (0, numeral_1.default)(nm).format(fm);
    }
    UIFormat.number = number;
    function percent(nm) {
        return nm === null || isNaN(nm) ? "" : (0, numeral_1.default)(nm > 1 ? nm / 100 : nm).format("0.00%");
    }
    UIFormat.percent = percent;
    function euro(nm) {
        if (nm === null || isNaN(nm))
            return "";
        return nm.toLocaleString('fr-BE', {
            minimumFractionDigits: 2,
            maximumFractionDigits: 2
        }) + '€';
    }
    UIFormat.euro = euro;
})(UIFormat = exports.UIFormat || (exports.UIFormat = {}));

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