let avatarHooks = {
  imgOnError: () => {
    let { photoUrl, onError } = this.props;
    AvatarBehaviour.invalidImageURLs.push(photoUrl);
    this.setState({ showAvatar: false });
    onError && onError();
  },

  imgOnLoad: () => {
    let { photoUrl } = this.props;
    AvatarBehaviour.validImageURLs.push(photoUrl);
    this.setState({ showAvatar: true });
  },

  getInitial: (nameTxt = "", defaultText) => {
    nameTxt = nameTxt && nameTxt.trim();
    let letters = null;
    let nametxts = nameTxt.split(" ");
    let letterfirst = nametxts[0].charAt(0);
    let letterSecond =
      nametxts.length > 1 ? nametxts[1].charAt(0) : nametxts[0].charAt(1);
    letters = letterfirst + letterSecond;
    return defaultText ? nameTxt : letters;
  },

  getContent: (text = "", textTransform, defaultText) => {
    let 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: (userImgString = "") => {
    let 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";
  }
};
export default avatarHooks;
