/* index.tsx generated by @compiled/babel-plugin v0.38.1 */
import _extends from "@babel/runtime/helpers/extends";
import "./index.compiled.css";
import * as React from 'react';
import { ax, ix } from "@compiled/react/runtime";
import { selectUnit } from '@formatjs/intl-utils';
import { FormattedMessage, useIntl } from 'react-intl-next';
import { messages } from '../../../../../../messages';
var styles = null;
var typeToDescriptorMap = {
  created: {
    relative: messages.created_on_relative,
    absolute: messages.created_on_absolute
  },
  modified: {
    relative: messages.modified_on_relative,
    absolute: messages.modified_on_absolute
  },
  sent: {
    relative: messages.sent_on_relative,
    absolute: 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 = 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 = 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(FormattedMessage, _extends({}, 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: ax(["_11c8wadc _1reo15vq _18m915vq _syazazsu _1e0ccj1k _1ul9idpf _1bto1l2s _1nmz1hna _1yyjkb7n _sudp1e54 _102k7vkz", fontSize !== undefined && fontOverrideStyleMap[fontSize], className])
  }, content);
};
export default BaseDateTimeElement;
export var toDateTimeProps = function toDateTimeProps(type, dateString) {
  return dateString ? {
    date: new Date(dateString),
    type: type
  } : undefined;
};