"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

exports.__esModule = true;
exports["default"] = void 0;

var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose"));

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

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

var _countUp = _interopRequireDefault(require("../count-up"));

var _context = _interopRequireDefault(require("../context"));

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

/**
 * 指标
 *
 * @class Indicator
 * @extends {PureComponent<IIndicator>}
 */
var Indicator = /*#__PURE__*/function (_PureComponent) {
  (0, _inheritsLoose2["default"])(Indicator, _PureComponent);

  function Indicator(props) {
    return _PureComponent.call(this, props) || this;
  }

  var _proto = Indicator.prototype;

  _proto.render = function render() {
    var _cssPrefix = this.context._cssPrefix;
    var _this$props = this.props,
        className = _this$props.className,
        forwardRef = _this$props.forwardRef,
        label = _this$props.label,
        value = _this$props.value,
        unit = _this$props.unit,
        type = _this$props.type,
        onClick = _this$props.onClick,
        onMouseEnter = _this$props.onMouseEnter,
        onMouseLeave = _this$props.onMouseLeave;
    var decimals = value.toString().split('.')[1];
    var len = decimals ? decimals.length : 0;
    return /*#__PURE__*/_react["default"].createElement("div", {
      ref: forwardRef,
      className: (0, _classnames["default"])(_cssPrefix + "indicator-wrapper", className),
      onClick: onClick,
      onMouseEnter: onMouseEnter,
      onMouseLeave: onMouseLeave
    }, /*#__PURE__*/_react["default"].createElement("div", {
      className: "" + _cssPrefix + type + "-indicator-title"
    }, label), /*#__PURE__*/_react["default"].createElement("div", {
      className: _cssPrefix + "indicator-value-wrapper"
    }, typeof value === 'number' ? /*#__PURE__*/_react["default"].createElement(_countUp["default"], {
      className: (0, _classnames["default"])(_cssPrefix + "data", "" + _cssPrefix + type + "-indicator-data"),
      endVal: value,
      decimalPlaces: len
    }) : /*#__PURE__*/_react["default"].createElement("span", {
      className: (0, _classnames["default"])(_cssPrefix + "data", "" + _cssPrefix + type + "-indicator-data")
    }, value), unit && /*#__PURE__*/_react["default"].createElement("span", {
      className: _cssPrefix + "indicator-unit"
    }, unit)));
  };

  return Indicator;
}(_react.PureComponent); // @ts-ignore


Indicator.defaultProps = {
  className: null,
  type: 'core',
  value: 0,
  onClick: function onClick() {},
  onMouseEnter: function onMouseEnter() {},
  onMouseLeave: function onMouseLeave() {}
}; // @ts-ignore

Indicator.category = 'Text';
Indicator.contextType = _context["default"];
var _default = Indicator;
exports["default"] = _default;