'use strict';

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

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 React__namespace = /*#__PURE__*/_interopNamespaceCompat(React);
var classNames__default = /*#__PURE__*/_interopDefaultCompat(classNames);

function _defineProperty(obj, key, value) {
  key = _toPropertyKey(key);
  if (key in obj) {
    Object.defineProperty(obj, key, {
      value: value,
      enumerable: true,
      configurable: true,
      writable: true
    });
  } else {
    obj[key] = value;
  }
  return obj;
}
function _extends() {
  _extends = Object.assign ? Object.assign.bind() : function (target) {
    for (var i = 1; i < arguments.length; i++) {
      var source = arguments[i];
      for (var key in source) {
        if (Object.prototype.hasOwnProperty.call(source, key)) {
          target[key] = source[key];
        }
      }
    }
    return target;
  };
  return _extends.apply(this, arguments);
}
function _objectWithoutPropertiesLoose(source, excluded) {
  if (source == null) return {};
  var target = {};
  var sourceKeys = Object.keys(source);
  var key, i;
  for (i = 0; i < sourceKeys.length; i++) {
    key = sourceKeys[i];
    if (excluded.indexOf(key) >= 0) continue;
    target[key] = source[key];
  }
  return target;
}
function _objectWithoutProperties(source, excluded) {
  if (source == null) return {};
  var target = _objectWithoutPropertiesLoose(source, excluded);
  var key, i;
  if (Object.getOwnPropertySymbols) {
    var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
    for (i = 0; i < sourceSymbolKeys.length; i++) {
      key = sourceSymbolKeys[i];
      if (excluded.indexOf(key) >= 0) continue;
      if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
      target[key] = source[key];
    }
  }
  return target;
}
function _toPrimitive(input, hint) {
  if (typeof input !== "object" || input === null) return input;
  var prim = input[Symbol.toPrimitive];
  if (prim !== undefined) {
    var res = prim.call(input, hint || "default");
    if (typeof res !== "object") return res;
    throw new TypeError("@@toPrimitive must return a primitive value.");
  }
  return (hint === "string" ? String : Number)(input);
}
function _toPropertyKey(arg) {
  var key = _toPrimitive(arg, "string");
  return typeof key === "symbol" ? key : String(key);
}

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(_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({
      className: classNames__default.default(css.root, _defineProperty({}, 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');
