"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MessagingAvatar = void 0;
var React = require("react");
var classNames = require("classnames");
require("./MessagingAvatar.less");
var utils_1 = require("./utils");
var cssClasses = {
    IMAGE: "Avatar--Image",
    CIRCLE: "Avatar--Circle",
    TEXT: "Avatar--Text",
};
/**
 * @deprecated Do not use. Instead, use [@clever/msg-avatar](https://github.com/Clever/clever-ui/tree/master/packages/msg-avatar)
 */
exports.MessagingAvatar = function (_a) {
    var className = _a.className, text = _a.text, color = _a.color, imageSrc = _a.imageSrc;
    // If an imageSrc is provided, it takes precedent over displaying text
    if (imageSrc) {
        return (React.createElement("img", { alt: "", "aria-hidden": "true", className: classNames(cssClasses.IMAGE, className), src: imageSrc }));
    }
    return (React.createElement("div", { className: classNames(cssClasses.CIRCLE, className), 
        // If defined, use color. Otherwise, use seed to determine color.
        style: {
            backgroundColor: color.color || "#" + _determineAvatarColor(color.seed),
        } },
        React.createElement("div", { className: cssClasses.TEXT }, _getInitialsFromText(text))));
};
// Helper function: Uses the convertNameToInitials util function to get
//  appropriate initials from the text prop, with a precautionary fallback.
function _getInitialsFromText(text) {
    try {
        return utils_1.convertNameToInitials(text);
    }
    catch (e) {
        return "";
    }
}
// Helper function: Uses a string as the seed to fairly randomly determine
//  the hex color for this avatar.
function _determineAvatarColor(determiningString) {
    var colorPool = [
        "C9F2F1",
        "FDB9C0",
        "FAE5B8",
        "D9BDFD",
        "B4EAD8",
        "BFCEFF",
        "FFBADE",
        "FDBD81",
    ];
    var hash = 0;
    for (var i = 0; i < determiningString.length; i++) {
        hash = determiningString.charCodeAt(i) + ((hash << 5) - hash);
        hash = hash & hash; // Converts to a 32bit int
    }
    return colorPool[Math.abs(hash % colorPool.length)];
}
