"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;

var React = _interopRequireWildcard(require("react"));

var _classnames = _interopRequireDefault(require("classnames"));

var _avatar = _interopRequireDefault(require("../avatar"));

var _configProvider = require("../config-provider");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj["default"] = obj; return newObj; } }

function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

function _extends() { _extends = Object.assign || 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 _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }

function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }

function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }

function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }

function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }

function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }

var __rest = void 0 && (void 0).__rest || function (s, e) {
  var t = {};

  for (var p in s) {
    if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
  }

  if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
    if (e.indexOf(p[i]) < 0) t[p[i]] = s[p[i]];
  }
  return t;
};

var colors = ['#17a589', '#148f77', '#117864', '#0e6251', '#16a085', '#138d75', '#117a65', '#0e6655', '#0b5345', '#239b56', '#1d8348', '#186a3b', '#27ae60', '#229954', '#1e8449', '#196f3d', '#145a32', '#2e86c1', '#2874a6', '#21618c', '#1b4f72', '#2980b9', '#2471a3', '#1f618d', '#1a5276', '#154360', '#9b59b6', '#884ea0', '#76448a', '#633974', '#512e5f', '#8e44ad', '#7d3c98', '#6c3483', '#5b2c6f', '#4a235a', '#34495e', '#5d6d7e', '#34495e', '#2e4053', '#283747', '#212f3c', '#1b2631', '#2c3e50', '#566573', '#2c3e50', '#273746', '#212f3d', '#1c2833', '#17202a', '#9a7d0a', '#7d6608', '#b9770e', '#9c640c', '#7e5109', '#af601a', '#935116', '#784212', '#d35400', '#ba4a00', '#a04000', '#873600', '#6e2c00', '#e74c3c', '#cb4335', '#b03a2e', '#943126', '#78281f', '#c0392b', '#cd6155', '#c0392b', '#a93226', '#922b21', '#7b241c', '#641e16', '#7b7d7d', '#797d7f', '#626567', '#717d7e', '#5f6a6a', '#4d5656', '#707b7c', '#616a6b', '#515a5a', '#424949'];

var Gravatar =
/*#__PURE__*/
function (_React$Component) {
  _inherits(Gravatar, _React$Component);

  function Gravatar() {
    var _this;

    _classCallCheck(this, Gravatar);

    _this = _possibleConstructorReturn(this, _getPrototypeOf(Gravatar).apply(this, arguments));

    _this.renderGravatar = function (_ref) {
      var getPrefixCls = _ref.getPrefixCls;

      var _a = _this.props,
          size = _a.size,
          className = _a.className,
          value = _a.value,
          style = _a.style,
          customizePrefixCls = _a.prefixCls,
          others = __rest(_a, ["size", "className", "value", "style", "prefixCls"]);

      var prefixCls = getPrefixCls('gravatar', customizePrefixCls);
      var nameSplit = String(value).toUpperCase().split(' ');
      var initials;

      if (nameSplit.length === 1) {
        initials = nameSplit[0] ? nameSplit[0].charAt(0) : '-';
      } else {
        initials = nameSplit[0].charAt(0) + nameSplit[1].charAt(0);
      }

      var charIndex = value.split('').map(function (char) {
        return char.charCodeAt(0);
      }).reduce(function (curr, prev) {
        return prev + curr;
      });
      var color = colors[charIndex % colors.length];
      return React.createElement(_avatar["default"], _extends({
        size: size,
        style: _extends({
          backgroundColor: color
        }, style),
        className: (0, _classnames["default"])(prefixCls, className)
      }, others), initials);
    };

    return _this;
  }

  _createClass(Gravatar, [{
    key: "render",
    value: function render() {
      return React.createElement(_configProvider.ConfigConsumer, null, this.renderGravatar);
    }
  }]);

  return Gravatar;
}(React.Component);

exports["default"] = Gravatar;
Gravatar.defaultProps = {
  size: 'default'
};