"use strict";

function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.NumberBadge = void 0;
var _react = _interopRequireDefault(require("react"));
var _styledComponents = _interopRequireWildcard(require("styled-components"));
var _ = require("../../../..");
var _utils = require("../../../../common/utils");
var _BaseBadge = require("../BaseBadge");
var _NumberBadge = require("./NumberBadge.constants");
var _excluded = ["badgeColor", "color", "children", "badgeSize", "animateOnChange", "symmetricShape"];
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: 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 _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 _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; }
var animation = (0, _styledComponents.css)(["@keyframes scale{0%{transform:scale(1);}1%{transform:scale(1.4);}100%{transform:scale(1);}}animation:scale 0.5s ease-out;"]);
var StyledBaseBadge = (0, _styledComponents.default)(_BaseBadge.BaseBadge).withConfig({
  displayName: "NumberBadge__StyledBaseBadge",
  componentId: "sc-rw3lr1-0"
})(["", " ", ""], function (_ref) {
  var $animateOnChange = _ref.$animateOnChange;
  return $animateOnChange ? animation : '';
}, function (p) {
  return p.$padding ? "padding: 0 ".concat(p.theme.spacing.unit(p.$padding), "px;") : '';
});
var NumberBadgeContent = function NumberBadgeContent(_ref2) {
  var children = _ref2.children,
    _color = _ref2.color,
    typographyType = _ref2.typographyType;
  if (typeof children === 'undefined') return null;
  if ((0, _utils.isFunction)(children)) return children();
  if ((0, _utils.isElement)(children)) return children;
  return _react.default.createElement(_.Typography, {
    type: typographyType,
    color: function color(t) {
      return _color ? _color(t) : t.color.badgeTextColor;
    },
    weight: "bold"
  }, children);
};
var NumberBadge = exports.NumberBadge = _react.default.forwardRef(function (_ref3, ref) {
  var _MAP_FONT_SIZE$number, _MAP_BADGE_PADDING$nu;
  var _ref3$badgeColor = _ref3.badgeColor,
    badgeColor = _ref3$badgeColor === void 0 ? function (t) {
      return t.color.badgeBackground;
    } : _ref3$badgeColor,
    _ref3$color = _ref3.color,
    color = _ref3$color === void 0 ? function (t) {
      return t.color.badgeTextColor;
    } : _ref3$color,
    children = _ref3.children,
    _ref3$badgeSize = _ref3.badgeSize,
    badgeSize = _ref3$badgeSize === void 0 ? 's' : _ref3$badgeSize,
    _ref3$animateOnChange = _ref3.animateOnChange,
    animateOnChange = _ref3$animateOnChange === void 0 ? false : _ref3$animateOnChange,
    _ref3$symmetricShape = _ref3.symmetricShape,
    symmetricShape = _ref3$symmetricShape === void 0 ? false : _ref3$symmetricShape,
    htmlProps = _objectWithoutProperties(_ref3, _excluded);
  var textColorOnParent = (0, _utils.isFunction)(children) || (0, _utils.isElement)(children);
  var numberBadgeSize = typeof badgeSize === 'number' ? badgeSize : _NumberBadge.NumberBadgeSize[badgeSize];
  var typographyType = (_MAP_FONT_SIZE$number = _NumberBadge.MAP_FONT_SIZE[numberBadgeSize]) !== null && _MAP_FONT_SIZE$number !== void 0 ? _MAP_FONT_SIZE$number : _NumberBadge.DEFAULT_TYPOGRAPHY_TYPE;
  var padding = (_MAP_BADGE_PADDING$nu = _NumberBadge.MAP_BADGE_PADDING[numberBadgeSize]) !== null && _MAP_BADGE_PADDING$nu !== void 0 ? _MAP_BADGE_PADDING$nu : _NumberBadge.DEFAULT_PADDING;
  return _react.default.createElement(StyledBaseBadge, _extends({}, htmlProps, {
    ref: ref,
    $animateOnChange: animateOnChange,
    $padding: padding,
    badgeSize: numberBadgeSize,
    badgeColor: badgeColor,
    symmetricShape: symmetricShape
  }, textColorOnParent && {
    color: color
  }), _react.default.createElement(NumberBadgeContent, {
    typographyType: typographyType,
    color: color
  }, children));
});