var _excluded = ["badgeColor", "color", "children", "badgeSize", "animateOnChange", "symmetricShape"];
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; }
import React from 'react';
import styled, { css } from 'styled-components';
import { Typography } from '../../../..';
import { isElement, isFunction } from '../../../../common/utils';
import { BaseBadge } from '../BaseBadge';
import { MAP_FONT_SIZE, MAP_BADGE_PADDING, DEFAULT_PADDING, DEFAULT_TYPOGRAPHY_TYPE, NumberBadgeSize } from './NumberBadge.constants';
var animation = css(["@keyframes scale{0%{transform:scale(1);}1%{transform:scale(1.4);}100%{transform:scale(1);}}animation:scale 0.5s ease-out;"]);
var StyledBaseBadge = styled(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 (isFunction(children)) return children();
  if (isElement(children)) return children;
  var textColor = function textColor(t) {
    return color ? color(t) : t.color.badgeTextColor;
  };
  return React.createElement(Typography, {
    type: typographyType,
    color: textColor,
    weight: "bold"
  }, children);
};
export var NumberBadge = React.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 = isFunction(children) || isElement(children);
  var numberBadgeSize = typeof badgeSize === 'number' ? badgeSize : NumberBadgeSize[badgeSize];
  var typographyType = (_MAP_FONT_SIZE$number = MAP_FONT_SIZE[numberBadgeSize]) !== null && _MAP_FONT_SIZE$number !== void 0 ? _MAP_FONT_SIZE$number : DEFAULT_TYPOGRAPHY_TYPE;
  var padding = (_MAP_BADGE_PADDING$nu = MAP_BADGE_PADDING[numberBadgeSize]) !== null && _MAP_BADGE_PADDING$nu !== void 0 ? _MAP_BADGE_PADDING$nu : DEFAULT_PADDING;
  return React.createElement(StyledBaseBadge, _extends({}, htmlProps, {
    ref: ref,
    $animateOnChange: animateOnChange,
    $padding: padding,
    badgeSize: numberBadgeSize,
    badgeColor: badgeColor,
    symmetricShape: symmetricShape
  }, textColorOnParent && {
    color: color
  }), React.createElement(NumberBadgeContent, {
    typographyType: typographyType,
    color: color
  }, children));
});