"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.processTimestamp = void 0;
const 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
 */
const antd_1 = require("antd");
const timeago_react_1 = __importDefault(require("timeago-react"));
function processTimestamp(props) {
    const { epoch, dateOnly } = props;
    let datetime = props.datetime;
    if (epoch && datetime == null) {
        datetime = new Date(epoch);
    }
    if (!datetime) {
        return "-";
    }
    if (typeof datetime == "string") {
        datetime = new Date(datetime);
        if (typeof datetime == "string")
            throw Error("bug");
    }
    const absoluteTimeDateOnly = datetime.toLocaleDateString(undefined, {
        year: "numeric",
        month: "short",
        day: "numeric",
    });
    const absoluteTimeFull = datetime.toLocaleString(undefined, {
        year: "numeric",
        month: "short",
        day: "numeric",
        hour: "numeric",
        minute: "numeric",
    });
    const timeShown = dateOnly ? absoluteTimeDateOnly : absoluteTimeFull;
    return { datetime, timeShown, absoluteTimeDateOnly, absoluteTimeFull };
}
exports.processTimestamp = processTimestamp;
function Timestamp(props) {
    const { style, absolute } = props;
    const data = processTimestamp(props);
    if (data === "-") {
        return (0, jsx_runtime_1.jsx)("span", { style: style, children: "-" });
    }
    const { datetime, timeShown, absoluteTimeFull } = data;
    if (absolute) {
        return ((0, jsx_runtime_1.jsx)(antd_1.Tooltip, { trigger: ["hover", "click"], title: absoluteTimeFull, children: (0, jsx_runtime_1.jsx)("span", { style: style, children: timeShown }) }));
    }
    return ((0, jsx_runtime_1.jsx)(antd_1.Tooltip, { 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