'use strict';

var React = require('react');

function FormatRelativeDateTime({ date: inputDate, }) {
    let dateObject;
    if (inputDate instanceof Date) {
        dateObject = inputDate;
    }
    else {
        dateObject = new Date(inputDate);
    }
    const now = Date.now() / 1000; //seconds
    const date = dateObject;
    const delta = now - date.getTime() / 1000; //seconds;
    switch (relativeTimeRange(delta)) {
        case "less than an hour":
            return React.createElement(React.Fragment, null, showMinutes(Math.round(delta / 60)));
        case "less then a day":
            return (React.createElement(React.Fragment, null, date.toLocaleTimeString(undefined, {
                hour: "numeric",
                minute: "numeric",
            })));
        case "less than a week":
            return React.createElement(React.Fragment, null, strFormatDate(date, { weekday: "short" }));
        case "less than a year":
            return React.createElement(React.Fragment, null, strFormatDate(date, { month: "short", day: "numeric" }));
        default:
            return (React.createElement(React.Fragment, null, strFormatDate(date, {
                month: "short",
                day: "numeric",
                year: "numeric",
            })));
    }
}
function relativeTimeRange(delta) {
    delta = delta / 60;
    if (delta < 60)
        return "less than an hour";
    delta = delta / 60;
    if (delta < 24)
        return "less then a day";
    delta = delta / 24;
    if (delta < 7)
        return "less than a week";
    delta = delta / 365;
    if (delta < 1)
        return "less than a year";
    return "a year or more";
}
function strFormatDate(date, options) {
    return date.toLocaleDateString(undefined, options);
}
function showMinutes(minutes) {
    if (minutes <= 1) {
        return "1 minute ago";
    }
    else {
        return minutes + " minutes ago";
    }
}

exports.FormatRelativeDateTime = FormatRelativeDateTime;
