/* index.tsx generated by @compiled/babel-plugin v0.39.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';
import { messages } from '../../../../../../messages';
const styles = null;
const 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
  }
};
const fontOverrideStyleMap = {
  'font.body': "_11c8fhey",
  'font.body.large': "_11c81d4k",
  'font.body.small': "_11c8wadc"
};
/**
 * 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
 */
const BaseDateTimeElement = ({
  date,
  name,
  className,
  type,
  testId = 'smart-element-date-time',
  text,
  hideDatePrefix = false,
  color,
  fontSize
}) => {
  const {
    formatRelativeTime,
    formatDate
  } = useIntl();
  if (!type || !date) {
    return null;
  }
  const isLongerThenWeek = Math.abs(date.getTime() - Date.now()) > 1000 * 60 * 60 * 24 * 7;
  let context;
  let typeVariant;
  if (isLongerThenWeek) {
    typeVariant = 'absolute';
    context = formatDate(date, {
      month: 'short',
      day: 'numeric',
      year: 'numeric'
    });
  } else {
    const {
      value,
      unit
    } = selectUnit(date, Date.now());
    typeVariant = 'relative';
    context = formatRelativeTime(value, unit, {
      numeric: 'auto'
    });
  }
  let content;
  if (hideDatePrefix) {
    content = context;
  } else if (text) {
    content = `${text} ${context}`;
  } else {
    content = /*#__PURE__*/React.createElement(FormattedMessage, _extends({}, typeToDescriptorMap[type][typeVariant], {
      values: {
        context
      }
    }));
  }
  return /*#__PURE__*/React.createElement("span", {
    style: {
      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 const toDateTimeProps = (type, dateString) => {
  return dateString ? {
    date: new Date(dateString),
    type
  } : undefined;
};