"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 _inputNumber = _interopRequireDefault(require("../input-number"));
require("./style");
var _jsxRuntime = require("react/jsx-runtime");
/**
 * 数字组件
 *
 * @param FieldDigitProps {
 *     text: number;
 *     moneySymbol?: string; }
 */
const FieldDigit = ({
  text,
  mode: type,
  render,
  renderFormItem,
  fieldProps,
  ...rest
}, ref) => {
  if (type === 'read') {
    const digit = new Intl.NumberFormat().format(Number(text));
    const dom = /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
      ref: ref,
      children: digit
    });
    if (render) {
      return render(text, {
        mode: type,
        ...fieldProps
      }, dom);
    }
    return dom;
  }
  if (type === 'edit' || type === 'update') {
    const dom = /*#__PURE__*/(0, _jsxRuntime.jsx)(_inputNumber.default, {
      ref: ref,
      min: 0,
      style: {
        width: '100%'
      },
      ...rest,
      ...fieldProps
    });
    if (renderFormItem) {
      return renderFormItem(text, {
        mode: type,
        ...fieldProps
      }, dom);
    }
    return dom;
  }
  return null;
};
var _default = /*#__PURE__*/_react.default.forwardRef(FieldDigit);
exports.default = _default;