'use strict';

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

var _extends = require('@babel/runtime/helpers/extends');
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
var React = require('react');
var classNames = require('clsx');

function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }

function _interopNamespaceCompat(e) {
    if (e && typeof e === 'object' && 'default' in e) return e;
    var n = Object.create(null);
    if (e) {
        Object.keys(e).forEach(function (k) {
            if (k !== 'default') {
                var d = Object.getOwnPropertyDescriptor(e, k);
                Object.defineProperty(n, k, d.get ? d : {
                    enumerable: true,
                    get: function () { return e[k]; }
                });
            }
        });
    }
    n.default = e;
    return Object.freeze(n);
}

var _extends__default = /*#__PURE__*/_interopDefaultCompat(_extends);
var _defineProperty__default = /*#__PURE__*/_interopDefaultCompat(_defineProperty);
var _objectWithoutProperties__default = /*#__PURE__*/_interopDefaultCompat(_objectWithoutProperties);
var React__namespace = /*#__PURE__*/_interopNamespaceCompat(React);
var classNames__default = /*#__PURE__*/_interopDefaultCompat(classNames);

var css = {"root":"Badge__root___QNSvz","root_variant_dot":"Badge__root_variant_dot___LQAyB","wrapper":"Badge__wrapper___uSbS1","wrapper_position_top-left":"Badge__wrapper_position_top-left___XQbSE","wrapper_position_top-right":"Badge__wrapper_position_top-right___RHHgB","wrapper_position_bottom-left":"Badge__wrapper_position_bottom-left___UCIFU","wrapper_position_bottom-right":"Badge__wrapper_position_bottom-right___MA0aH"};

var _excluded = ["value", "isShowZero", "max", "position", "variant", "children", "className"];
/**
 * Небольшой значок в правом верхнем углу своего дочернего элемента
 */
var Badge = /*#__PURE__*/React__namespace.forwardRef(function (_ref, ref) {
  var value = _ref.value,
    _ref$isShowZero = _ref.isShowZero,
    isShowZero = _ref$isShowZero === void 0 ? false : _ref$isShowZero,
    _ref$max = _ref.max,
    max = _ref$max === void 0 ? 9 : _ref$max,
    _ref$position = _ref.position,
    position = _ref$position === void 0 ? 'top-right' : _ref$position,
    variant = _ref.variant,
    children = _ref.children,
    className = _ref.className,
    props = _objectWithoutProperties__default.default(_ref, _excluded);
  var wrapperPosition = position || 'top-right';
  var badgeContent = value;
  var badgeResult = null;
  if (Number.isInteger(max) && Number(value) > max) {
    badgeContent = "".concat(max, "+");
  }
  if (badgeContent || badgeContent === 0 && isShowZero) {
    badgeResult = /*#__PURE__*/React__namespace.createElement("span", _extends__default.default({
      className: classNames__default.default(css.root, _defineProperty__default.default({}, css.root_variant_dot, variant === 'dot'), className),
      ref: ref,
      "data-qaid": "badge",
      "data-testid": "badge"
    }, props), badgeContent);
  }
  if (!!children) {
    return /*#__PURE__*/React__namespace.createElement("div", {
      className: classNames__default.default(css.wrapper, css["wrapper_position_".concat(wrapperPosition)])
    }, children, badgeResult);
  }
  return badgeResult;
});
Badge.displayName = 'Badge';

exports.Badge = Badge;

require('./style.development.css');
