"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = Timestamp;
var _react = _interopRequireDefault(require("react"));
var _moment = _interopRequireDefault(require("moment"));
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
/**
 * A note on UTC, and the `utc` prop being used for both input intepretation and output format:
 *
 * When using moment.js, it's effectively impossible to force reading something in as UTC and
 * then also have formatting happen in the user's local time.
 *
 * This is because `.utc()` both changes how a timestamp is interpreted and the moment object's
 * formatting rules. Once `.utc()` has been called, the only option is call `.local()`, but that
 * converts to the user's _current_ local offset from UTC. That isn't guaranteed to be the same
 * offset in future or past dates (due to DST) so we risk showing the wrong time.
 *
 * The majority use case for <Timestamp/> is to display dates _in UTC_ anyway, but if it is ever necessary
 * to display a timestamp in user-local time, just pass utc=false and ensure that input timestamps are in
 * ISO 8601 with explicit offsets.
 */

/** Simple component for rendering timestamps in a consistent manner */

function Timestamp({
  timestamp,
  outputFormat = 'YYYY-MM-DD HH:mm:ss',
  utc = true,
  showTimezoneLabel = utc,
  testId = 'timestamp'
}) {
  const momentInstance = utc ? _moment.default.utc(timestamp) : (0, _moment.default)(timestamp);

  // in utc mode with just use a literal, otherwise we just show the offset (e.g. +02:00)
  const timezoneLabel = utc ? 'UTC' : `UTC ${momentInstance.format('Z')}`;
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)("span", {
    "test-id": testId,
    children: [momentInstance.format(outputFormat), showTimezoneLabel && ` (${timezoneLabel})`]
  });
}