"use strict";
var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var jsx_runtime_1 = require("react/jsx-runtime");
/*
 *  This file is part of CoCalc: Copyright © 2022 Sagemath, Inc.
 *  License: AGPLv3 s.t. "Commons Clause" – see LICENSE.md for details
 */
var antd_1 = require("antd");
var timeago_react_1 = __importDefault(require("timeago-react"));
function Timestamp(props) {
    var epoch = props.epoch, style = props.style, absolute = props.absolute, dateOnly = props.dateOnly;
    var datetime = props.datetime;
    if (epoch && datetime == null) {
        datetime = new Date(epoch);
    }
    if (!datetime) {
        return (0, jsx_runtime_1.jsx)("span", __assign({ style: style }, { children: "-" }));
    }
    if (typeof datetime == "string") {
        datetime = new Date(datetime);
        if (typeof datetime == "string")
            throw Error("bug");
    }
    var absoluteTimeDateOnly = datetime.toLocaleDateString(undefined, {
        year: "numeric",
        month: "short",
        day: "numeric",
    });
    var absoluteTimeFull = datetime.toLocaleString(undefined, {
        year: "numeric",
        month: "short",
        day: "numeric",
        hour: "numeric",
        minute: "numeric",
    });
    var timeShown = dateOnly ? absoluteTimeDateOnly : absoluteTimeFull;
    if (absolute) {
        return ((0, jsx_runtime_1.jsx)(antd_1.Tooltip, __assign({ trigger: ["hover", "click"], title: absoluteTimeFull }, { children: (0, jsx_runtime_1.jsx)("span", __assign({ style: style }, { children: timeShown })) })));
    }
    return ((0, jsx_runtime_1.jsx)(antd_1.Tooltip, __assign({ trigger: ["hover", "click"], title: timeShown }, { children: (0, jsx_runtime_1.jsx)(timeago_react_1.default, { style: style, datetime: datetime }) })));
}
exports.default = Timestamp;
//# sourceMappingURL=timestamp.js.map