"use strict";

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

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard")["default"];

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;

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

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

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

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

var _reactNode = require("../_util/reactNode");

var _SingleNumber = _interopRequireDefault(require("./SingleNumber"));

var _ConfigContext = _interopRequireDefault(require("../config-provider/ConfigContext"));

var _excluded = ["prefixCls", "count", "className", "style", "title", "hidden", "component", "children"];

var ScrollNumber = function ScrollNumber(_ref) {
  var customizePrefixCls = _ref.prefixCls,
      count = _ref.count,
      className = _ref.className,
      style = _ref.style,
      title = _ref.title,
      hidden = _ref.hidden,
      _ref$component = _ref.component,
      component = _ref$component === void 0 ? 'sup' : _ref$component,
      children = _ref.children,
      restProps = (0, _objectWithoutProperties2["default"])(_ref, _excluded);

  var _useContext = (0, _react.useContext)(_ConfigContext["default"]),
      getPrefixCls = _useContext.getPrefixCls;

  var prefixCls = getPrefixCls('scroll-number', customizePrefixCls); // ============================ Render ============================

  var newProps = (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, restProps), {}, {
    'data-show': !hidden,
    style: style,
    className: (0, _classnames["default"])(prefixCls, className),
    title: title
  }); // Only integer need motion

  var numberNodes = count;

  if (count && Number(count) % 1 === 0) {
    var numberList = String(count).split('');
    numberNodes = numberList.map(function (num, i) {
      return /*#__PURE__*/_react["default"].createElement(_SingleNumber["default"], {
        prefixCls: prefixCls,
        count: Number(count),
        value: num,
        // eslint-disable-next-line react/no-array-index-key
        key: numberList.length - i
      });
    });
  }

  if (style && style.borderColor) {
    newProps.style = (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, style), {}, {
      boxShadow: "0 0 0 1px ".concat(style.borderColor, " inset")
    });
  }

  if (children) {
    return (0, _reactNode.cloneElement)(children, function (oriProps) {
      return {
        className: (0, _classnames["default"])("".concat(prefixCls, "-custom-component"), oriProps && oriProps.className)
      };
    });
  }

  return /*#__PURE__*/(0, _react.createElement)(component, newProps, numberNodes);
};

ScrollNumber.displayName = 'ScrollNumber';

var _default = /*#__PURE__*/(0, _react.memo)(ScrollNumber);

exports["default"] = _default;
//# sourceMappingURL=ScrollNumber.js.map
