import "choerodon-ui/lib/tooltip/style";
import _Tooltip from "choerodon-ui/lib/tooltip";
import React, { Fragment, memo } from 'react';
import TimeAgo from 'timeago-react';
import { Choerodon } from '@choerodon/boot';
import { formatDate } from "../../utils";

function TimePopover(_ref) {
  var datetime = _ref.datetime,
      placement = _ref.placement;
  var time;

  if (datetime) {
    // eslint-disable-next-line no-underscore-dangle
    if (typeof datetime === 'object' && datetime._isAMomentObject) {
      time = datetime.format();
    } else if (typeof datetime === 'string') {
      time = new Date(datetime.replace(/-/g, '/')).getTime();
    }
  }

  return /*#__PURE__*/React.createElement(Fragment, null, time ? /*#__PURE__*/React.createElement(_Tooltip, {
    placement: placement,
    title: formatDate(time)
  }, /*#__PURE__*/React.createElement(TimeAgo, {
    datetime: time,
    locale: Choerodon.getMessage('zh_CN', 'en')
  })) : null);
}

TimePopover.defaultProps = {
  placement: 'top'
};
export default /*#__PURE__*/memo(TimePopover);