'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var _rollupPluginBabelHelpers = require('../../_virtual/_rollupPluginBabelHelpers.js');
var React = require('react');
var index = require('../../utils/index.js');
var base = require('./variations/_view/base.js');
var base$1 = require('./variations/_size/base.js');
var Counter_styles = require('./Counter.styles.js');
var Counter_tokens = require('./Counter.tokens.js');

function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }

var React__default = /*#__PURE__*/_interopDefault(React);

var _excluded = ["count", "maxCount", "size", "view", "className"];
var MIN_COUNT = 0;
var counterRoot = function counterRoot(Root) {
  return /*#__PURE__*/React.forwardRef(function (props, ref) {
    var count = props.count,
      maxCount = props.maxCount,
      size = props.size,
      view = props.view,
      className = props.className,
      rest = _rollupPluginBabelHelpers.objectWithoutProperties(props, _excluded);
    var currentCount = count < MIN_COUNT ? MIN_COUNT : count;
    var currentMaxCount = maxCount && maxCount < MIN_COUNT ? MIN_COUNT : maxCount;
    var isCurrentCountOneDigit = currentCount >= 0 && currentCount < 10;
    var isCurrentMaxCountExceeded = currentMaxCount && currentCount > currentMaxCount;
    var content = isCurrentMaxCountExceeded ? "".concat(currentMaxCount, "+") : currentCount;
    var roundClass = !isCurrentMaxCountExceeded && isCurrentCountOneDigit ? Counter_tokens.classes.round : undefined;
    return /*#__PURE__*/React__default.default.createElement(Root, _rollupPluginBabelHelpers.extends({
      ref: ref,
      view: view,
      size: size,
      count: count,
      className: index.cx(roundClass, className)
    }, rest), content);
  });
};
var counterConfig = {
  name: 'Counter',
  tag: 'div',
  layout: counterRoot,
  base: Counter_styles.base,
  variations: {
    view: {
      css: base.base
    },
    size: {
      css: base$1.base
    }
  },
  defaults: {
    view: 'primary',
    size: 'xs'
  }
};

exports.counterConfig = counterConfig;
exports.counterRoot = counterRoot;
