/* index.tsx generated by @compiled/babel-plugin v0.38.1 */
"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.toDateTimeProps = exports.default = void 0;
require("./index.compiled.css");
var React = _interopRequireWildcard(require("react"));
var _runtime = require("@compiled/react/runtime");
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _intlUtils = require("@formatjs/intl-utils");
var _reactIntlNext = require("react-intl-next");
var _messages = require("../../../../../../messages");
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
var styles = null;
var typeToDescriptorMap = {
  created: {
    relative: _messages.messages.created_on_relative,
    absolute: _messages.messages.created_on_absolute
  },
  modified: {
    relative: _messages.messages.modified_on_relative,
    absolute: _messages.messages.modified_on_absolute
  },
  sent: {
    relative: _messages.messages.sent_on_relative,
    absolute: _messages.messages.sent_on_absolute
  }
};
var fontOverrideStyleMap = {
  'font.body': "_11c8fhey",
  'font.body.large': "_11c81d4k",
  'font.body.small': "_11c8wadc",
  'font.body.UNSAFE_small': "_11c8rymc"
};
/**
 * A base element that displays an ISO Timestamp in text.
 * @internal
 * @param {BaseDateTimeElementProps} BaseDateTimeElementProps - The props necessary for the DateTime element.
 * @see CreatedOn
 * @see ModifiedOn
 * @see SentOn
 */
var BaseDateTimeElement = function BaseDateTimeElement(_ref) {
  var date = _ref.date,
    name = _ref.name,
    className = _ref.className,
    type = _ref.type,
    _ref$testId = _ref.testId,
    testId = _ref$testId === void 0 ? 'smart-element-date-time' : _ref$testId,
    text = _ref.text,
    _ref$hideDatePrefix = _ref.hideDatePrefix,
    hideDatePrefix = _ref$hideDatePrefix === void 0 ? false : _ref$hideDatePrefix,
    color = _ref.color,
    fontSize = _ref.fontSize;
  var _useIntl = (0, _reactIntlNext.useIntl)(),
    formatRelativeTime = _useIntl.formatRelativeTime,
    formatDate = _useIntl.formatDate;
  if (!type || !date) {
    return null;
  }
  var isLongerThenWeek = Math.abs(date.getTime() - Date.now()) > 1000 * 60 * 60 * 24 * 7;
  var context;
  var typeVariant;
  if (isLongerThenWeek) {
    typeVariant = 'absolute';
    context = formatDate(date, {
      month: 'short',
      day: 'numeric',
      year: 'numeric'
    });
  } else {
    var _selectUnit = (0, _intlUtils.selectUnit)(date, Date.now()),
      value = _selectUnit.value,
      unit = _selectUnit.unit;
    typeVariant = 'relative';
    context = formatRelativeTime(value, unit, {
      numeric: 'auto'
    });
  }
  var content;
  if (hideDatePrefix) {
    content = context;
  } else if (text) {
    content = "".concat(text, " ").concat(context);
  } else {
    content = /*#__PURE__*/React.createElement(_reactIntlNext.FormattedMessage, (0, _extends2.default)({}, typeToDescriptorMap[type][typeVariant], {
      values: {
        context: context
      }
    }));
  }
  return /*#__PURE__*/React.createElement("span", {
    style: {
      color: color
    },
    "data-separator": true,
    "data-smart-element": name,
    "data-smart-element-date-time": true,
    "data-testid": testId
    // eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop
    ,
    className: (0, _runtime.ax)(["_11c8wadc _1reo15vq _18m915vq _syazazsu _1e0ccj1k _1ul9idpf _1bto1l2s _1nmz1hna _1yyjkb7n _sudp1e54 _102k7vkz", fontSize !== undefined && fontOverrideStyleMap[fontSize], className])
  }, content);
};
var _default = exports.default = BaseDateTimeElement;
var toDateTimeProps = exports.toDateTimeProps = function toDateTimeProps(type, dateString) {
  return dateString ? {
    date: new Date(dateString),
    type: type
  } : undefined;
};