import { objectWithoutProperties as _objectWithoutProperties, extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js';
import React__default, { forwardRef } from 'react';
import { cx } from '../../utils/index.js';
import { base as base$1 } from './variations/_view/base.js';
import { base as base$2 } from './variations/_size/base.js';
import { base } from './Counter.styles.js';
import { classes } from './Counter.tokens.js';

var _excluded = ["count", "maxCount", "size", "view", "className"];
var MIN_COUNT = 0;
var counterRoot = function counterRoot(Root) {
  return /*#__PURE__*/forwardRef(function (props, ref) {
    var count = props.count,
      maxCount = props.maxCount,
      size = props.size,
      view = props.view,
      className = props.className,
      rest = _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 ? classes.round : undefined;
    return /*#__PURE__*/React__default.createElement(Root, _extends({
      ref: ref,
      view: view,
      size: size,
      count: count,
      className: cx(roundClass, className)
    }, rest), content);
  });
};
var counterConfig = {
  name: 'Counter',
  tag: 'div',
  layout: counterRoot,
  base: base,
  variations: {
    view: {
      css: base$1
    },
    size: {
      css: base$2
    }
  },
  defaults: {
    view: 'primary',
    size: 'xs'
  }
};

export { counterConfig, counterRoot };
