"use strict";

exports.__esModule = true;
exports.default = DateTimeAgo;

var _react = _interopRequireDefault(require("react"));

var _reactTimeago = _interopRequireDefault(require("react-timeago"));

var _it = _interopRequireDefault(require("react-timeago/lib/language-strings/it"));

var _buildFormatter = _interopRequireDefault(require("react-timeago/lib/formatters/buildFormatter"));

var _styles = require("@mui/material/styles");

var _material = require("@mui/material");

var _Icon = _interopRequireDefault(require("@mui/material/Icon"));

var _reactIntl = require("react-intl");

var _classnames = _interopRequireDefault(require("classnames"));

const _excluded = ["className", "live", "date", "showStartIcon"];

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }

const PREFIX = 'SCDateTimeAgo';
const classes = {
  root: `${PREFIX}-root`
};
const Root = (0, _styles.styled)(_material.Box, {
  name: PREFIX,
  slot: 'Root',
  overridesResolver: (props, styles) => [styles.root]
})(() => ({
  width: 'auto',
  display: 'inline-flex',
  alignItems: 'center',
  marginRight: 3,
  '& .MuiIcon-root': {
    fontSize: '18px',
    marginRight: 2
  },
  '& .MuiTypography-root': {
    lineHeight: 1.8
  }
}));
const formatter = (0, _buildFormatter.default)(_it.default);

function DateTimeAgo(props) {
  // PROPS
  const {
    className,
    live = true,
    date = null,
    showStartIcon = true
  } = props,
        rest = _objectWithoutPropertiesLoose(props, _excluded); // INTL


  const intl = (0, _reactIntl.useIntl)();
  /**
   * Renders root object (if date obj)
   */

  if (date) {
    return /*#__PURE__*/_react.default.createElement(Root, _extends({
      className: (0, _classnames.default)(classes.root, className)
    }, rest), showStartIcon && /*#__PURE__*/_react.default.createElement(_Icon.default, null, "access_time"), /*#__PURE__*/_react.default.createElement(_material.Tooltip, {
      title: `${intl.formatDate(date, {
        year: 'numeric',
        month: 'numeric',
        day: 'numeric',
        hour: 'numeric',
        minute: 'numeric'
      })}`
    }, /*#__PURE__*/_react.default.createElement(_material.Typography, {
      variant: 'body2',
      component: 'span'
    }, /*#__PURE__*/_react.default.createElement(_reactTimeago.default, {
      date: date,
      live: live,
      formatter: formatter
    }))));
  }

  return null;
}