import { formatDistance, formatDistanceStrict, isValid, parseISO, toDate } from "date-fns";
import moment from "moment";
import numeral from "numeral";
export var UIFormat;
(function (UIFormat) {
    function parseDate(dt) {
        return typeof dt === "string" ? parseISO(dt) : dt;
    }
    UIFormat.parseDate = parseDate;
    function date(dt, ft) {
        if (ft === void 0) { ft = "DD/MM/yyyy"; }
        dt = parseDate(dt);
        return !dt || !isValid(dt)
            ? null
            : moment(dt).format(ft);
    }
    UIFormat.date = date;
    function time(dt, ft) {
        if (ft === void 0) { ft = "HH:mm"; }
        dt = parseDate(dt);
        return !dt || !isValid(dt)
            ? null
            : moment(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 || !isValid(dt)
            ? null
            : moment(dt).format(ft);
    }
    UIFormat.datetime = datetime;
    function utcDate(dt) {
        dt = parseDate(dt);
        return !dt || !isValid(dt) ? null : toDate(dt).toISOString();
    }
    UIFormat.utcDate = utcDate;
    function dateToISO(dt) {
        dt = parseDate(dt);
        return !dt || !isValid(dt)
            ? null
            : moment(dt).format("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
    }
    UIFormat.dateToISO = dateToISO;
    function age(dt) {
        dt = parseDate(dt);
        return !dt || !isValid(dt) ? "" : formatDistanceStrict(dt, new Date());
    }
    UIFormat.age = age;
    function fromNow(dt) {
        dt = parseDate(dt);
        return !dt || !isValid(dt) ? "" : 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) ? "" : numeral(nm).format(fm);
    }
    UIFormat.number = number;
    function percent(nm) {
        return nm === null || isNaN(nm) ? "" : numeral(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 || (UIFormat = {}));

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