"use strict";

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

var _this = void 0;

var avatarHooks = {
  imgOnError: function imgOnError() {
    var _this$props = _this.props,
        photoUrl = _this$props.photoUrl,
        onError = _this$props.onError;
    AvatarBehaviour.invalidImageURLs.push(photoUrl);

    _this.setState({
      showAvatar: false
    });

    onError && onError();
  },
  imgOnLoad: function imgOnLoad() {
    var photoUrl = _this.props.photoUrl;
    AvatarBehaviour.validImageURLs.push(photoUrl);

    _this.setState({
      showAvatar: true
    });
  },
  getInitial: function getInitial() {
    var nameTxt = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "";
    var defaultText = arguments.length > 1 ? arguments[1] : undefined;
    nameTxt = nameTxt && nameTxt.trim();
    var letters = null;
    var nametxts = nameTxt.split(" ");
    var letterfirst = nametxts[0].charAt(0);
    var letterSecond = nametxts.length > 1 ? nametxts[1].charAt(0) : nametxts[0].charAt(1);
    letters = letterfirst + letterSecond;
    return defaultText ? nameTxt : letters;
  },
  getContent: function getContent() {
    var text = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "";
    var textTransform = arguments.length > 1 ? arguments[1] : undefined;
    var defaultText = arguments.length > 2 ? arguments[2] : undefined;
    var textTransFormed = avatarHooks.getInitial(text, defaultText);

    if (textTransform == "upperCase") {
      textTransFormed = textTransFormed.toUpperCase();
    } else if (textTransform == "lowerCase") {
      textTransFormed = textTransFormed.toLowerCase();
    } else if (textTransform == "capitalize") {
      textTransFormed = (textTransFormed.charAt(0) || "?").toLocaleUpperCase() + (textTransFormed.substr(1) || "?").toLowerCase();
    }

    return textTransFormed;
  },
  getAbbr: function getAbbr() {
    var userImgString = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "";
    var numberValue = Number(userImgString);

    if (!isNaN(numberValue)) {
      return "number";
    } else if (userImgString.match(/^[-!$%^&*#()_+|~=`{}\[\]:";'<>?,.\/]+$/)) {
      return "special";
    }

    userImgString = userImgString.substring(0, 1).toLowerCase();

    if (userImgString.match(/[^a-zA-Z]/g) == null) {
      return userImgString;
    }

    return "other";
  }
};
var _default = avatarHooks;
exports["default"] = _default;