"use strict";

function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }

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

var _react = _interopRequireDefault(require("react"));

var _AvatarModule = _interopRequireDefault(require("./Avatar.module.css"));

var _getCompliedClassName3 = _interopRequireDefault(require("../../utils/getCompliedClassName"));

var _Avatar = _interopRequireWildcard(require("./Avatar.propTypes"));

var _Avatar2 = _interopRequireDefault(require("./Avatar.constantProps"));

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

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

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

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

function Avatar(props) {
  var _getCompliedClassName, _getCompliedClassName2;

  var shape = props.shape,
      size = props.size,
      color = props.color,
      text = props.text,
      photoUrl = props.photoUrl,
      floatingLayer = props.floatingLayer,
      floatingLayerText = props.floatingLayerText,
      floatingLayerAlign = props.floatingLayerAlign,
      customClassName = props.customClassName,
      onError = props.onError,
      onLoad = props.onLoad,
      showAvatar = props.showAvatar,
      getContent = props.getContent; // icon-support , getContent

  var className = (0, _getCompliedClassName3["default"])(customClassName, (_getCompliedClassName = {}, _defineProperty(_getCompliedClassName, _AvatarModule["default"].base, true), _defineProperty(_getCompliedClassName, _AvatarModule["default"][color], !!color), _defineProperty(_getCompliedClassName, _AvatarModule["default"][shape], !!shape), _defineProperty(_getCompliedClassName, _AvatarModule["default"][size], !!size), _getCompliedClassName), (_getCompliedClassName2 = {}, _defineProperty(_getCompliedClassName2, customClassName.shape, !!customClassName.shape), _defineProperty(_getCompliedClassName2, customClassName.size, !!customClassName.size), _defineProperty(_getCompliedClassName2, customClassName.color, !!customClassName.color), _getCompliedClassName2));

  if ((floatingLayer || floatingLayerText) && showAvatar) {
    return /*#__PURE__*/_react["default"].createElement("span", {
      className: _AvatarModule["default"].container
    }, /*#__PURE__*/_react["default"].createElement("span", {
      className: "".concat(floatingLayerText ? _AvatarModule["default"].floatinglayer : null, " ").concat(floatingLayerText ? _AvatarModule["default"][floatingLayerAlign + "_" + size] : null)
    }, floatingLayer ? null : floatingLayerText, floatingLayer ? floatingLayer : null), photoUrl ? /*#__PURE__*/_react["default"].createElement("img", {
      src: photoUrl,
      onError: onError && onError,
      className: className,
      onLoad: onLoad && onLoad
    }) : /*#__PURE__*/_react["default"].createElement("span", {
      className: className
    }, getContent(text, "upperCase")));
  } else if (photoUrl && showAvatar) {
    return /*#__PURE__*/_react["default"].createElement("img", {
      src: photoUrl,
      onError: onError && onError,
      className: className,
      onLoad: onLoad && onLoad
    });
  }

  return /*#__PURE__*/_react["default"].createElement("span", {
    className: className
  }, getContent(text, "upperCase"));
}

Avatar.propTypes = _Avatar["default"];
Avatar.defaultProps = _Avatar.defaultProps;
Avatar.propsDescription = _Avatar.propsDescription;
Avatar.constantProps = _Avatar2["default"];