import * as _vue from "vue";
import padEnd from 'lodash/padEnd';
import { createVNode } from 'vue';

var Number = function Number(_, _ref) {
  var attrs = _ref.attrs;
  var value = attrs.value,
      formatter = attrs.formatter,
      precision = attrs.precision,
      decimalSeparator = attrs.decimalSeparator,
      _attrs$groupSeparator = attrs.groupSeparator,
      groupSeparator = _attrs$groupSeparator === void 0 ? '' : _attrs$groupSeparator,
      prefixCls = attrs.prefixCls;
  var valueNode;

  if (typeof formatter === 'function') {
    // Customize formatter
    valueNode = formatter({
      value: value,
      h: createVNode
    });
  } else {
    // Internal formatter
    var val = String(value);
    var cells = val.match(/^(-?)(\d*)(\.(\d+))?$/); // Process if illegal number

    if (!cells) {
      valueNode = val;
    } else {
      var negative = cells[1];

      var _int = cells[2] || '0';

      var decimal = cells[4] || '';
      _int = _int.replace(/\B(?=(\d{3})+(?!\d))/g, groupSeparator);

      if (typeof precision === 'number') {
        decimal = padEnd(decimal, precision, '0').slice(0, precision);
      }

      if (decimal) {
        decimal = "".concat(decimalSeparator).concat(decimal);
      }

      valueNode = [_vue.createVNode("span", {
        "key": "int",
        "class": "".concat(prefixCls, "-content-value-int")
      }, [negative, _int]), decimal && _vue.createVNode("span", {
        "key": "decimal",
        "class": "".concat(prefixCls, "-content-value-decimal")
      }, [decimal])];
    }
  }

  return _vue.createVNode("span", {
    "class": "".concat(prefixCls, "-content-value")
  }, [valueNode]);
};

export default Number;