"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = _interopRequireDefault(require("react"));
var _moment = _interopRequireDefault(require("moment"));
var _tooltip = _interopRequireDefault(require("../tooltip"));
var _datePicker = _interopRequireDefault(require("../date-picker"));
var _utils = require("../utils");
var _wauProvider = require("../wau-provider");
require("./style");
var _jsxRuntime = require("react/jsx-runtime");
/**
 * 与当前的时间进行比较 http://momentjs.cn/docs/displaying/fromnow.html
 *
 * @param
 */const FieldFromNow = ({
  text,
  mode,
  render,
  renderFormItem,
  format,
  fieldProps
}) => {
  const intl = (0, _wauProvider.useIntl)();
  if (mode === 'read') {
    const dom = /*#__PURE__*/(0, _jsxRuntime.jsx)(_tooltip.default, {
      title: (0, _moment.default)(text).format(format || 'YYYY-MM-DD HH:mm:ss'),
      children: (0, _moment.default)(text).fromNow()
    });
    if (render) {
      return render(text, {
        mode,
        ...fieldProps
      }, /*#__PURE__*/(0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
        children: dom
      }));
    }
    return /*#__PURE__*/(0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
      children: dom
    });
  }
  if (mode === 'edit' || mode === 'update') {
    const placeholder = intl.getMessage('tableForm.selectPlaceholder', '请选择');
    const momentValue = (0, _utils.parseValueToMoment)(fieldProps.value);
    const dom = /*#__PURE__*/(0, _jsxRuntime.jsx)(_datePicker.default, {
      placeholder: placeholder,
      ...fieldProps,
      value: momentValue
    });
    if (renderFormItem) {
      return renderFormItem(text, {
        mode,
        ...fieldProps
      }, dom);
    }
    return dom;
  }
  return null;
};
var _default = FieldFromNow;
exports.default = _default;