"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var Persona_types_1 = require("./Persona.types");
/**
 * These colors are considered reserved colors and can only be set with overrides:
 * - Red is a color that often has a special meaning.
 * - Transparent is not intended to be used with typical initials due to accessibility issues,
 *   its primary use is for Facepile overflow buttons.
 */
var COLOR_SWATCHES_LOOKUP = [
    Persona_types_1.PersonaInitialsColor.lightGreen,
    Persona_types_1.PersonaInitialsColor.lightBlue,
    Persona_types_1.PersonaInitialsColor.lightPink,
    Persona_types_1.PersonaInitialsColor.green,
    Persona_types_1.PersonaInitialsColor.darkGreen,
    Persona_types_1.PersonaInitialsColor.pink,
    Persona_types_1.PersonaInitialsColor.magenta,
    Persona_types_1.PersonaInitialsColor.purple,
    Persona_types_1.PersonaInitialsColor.black,
    Persona_types_1.PersonaInitialsColor.teal,
    Persona_types_1.PersonaInitialsColor.blue,
    Persona_types_1.PersonaInitialsColor.darkBlue,
    Persona_types_1.PersonaInitialsColor.orange,
    Persona_types_1.PersonaInitialsColor.darkRed
];
var COLOR_SWATCHES_NUM_ENTRIES = COLOR_SWATCHES_LOOKUP.length;
function getInitialsColorFromName(displayName) {
    var color = Persona_types_1.PersonaInitialsColor.blue;
    if (!displayName) {
        return color;
    }
    var hashCode = 0;
    for (var iLen = displayName.length - 1; iLen >= 0; iLen--) {
        var ch = displayName.charCodeAt(iLen);
        var shift = iLen % 8;
        // tslint:disable-next-line:no-bitwise
        hashCode ^= (ch << shift) + (ch >> (8 - shift));
    }
    color = COLOR_SWATCHES_LOOKUP[hashCode % COLOR_SWATCHES_NUM_ENTRIES];
    return color;
}
function personaInitialsColorToHexCode(personaInitialsColor) {
    switch (personaInitialsColor) {
        case Persona_types_1.PersonaInitialsColor.lightBlue:
            return '#6BA5E7';
        case Persona_types_1.PersonaInitialsColor.blue:
            return '#2D89EF';
        case Persona_types_1.PersonaInitialsColor.darkBlue:
            return '#2B5797';
        case Persona_types_1.PersonaInitialsColor.teal:
            return '#00ABA9';
        case Persona_types_1.PersonaInitialsColor.lightGreen:
            return '#99B433';
        case Persona_types_1.PersonaInitialsColor.green:
            return '#00A300';
        case Persona_types_1.PersonaInitialsColor.darkGreen:
            return '#1E7145';
        case Persona_types_1.PersonaInitialsColor.lightPink:
            return '#E773BD';
        case Persona_types_1.PersonaInitialsColor.pink:
            return '#FF0097';
        case Persona_types_1.PersonaInitialsColor.magenta:
            return '#7E3878';
        case Persona_types_1.PersonaInitialsColor.purple:
            return '#603CBA';
        case Persona_types_1.PersonaInitialsColor.black:
            return '#1D1D1D';
        case Persona_types_1.PersonaInitialsColor.orange:
            return '#DA532C';
        case Persona_types_1.PersonaInitialsColor.red:
            return '#EE1111';
        case Persona_types_1.PersonaInitialsColor.darkRed:
            return '#B91D47';
        case Persona_types_1.PersonaInitialsColor.transparent:
            return 'transparent';
    }
}
function initialsColorPropToColorCode(props) {
    var primaryText = props.primaryText, text = props.text;
    var initialsColor = props.initialsColor;
    var initialsColorCode;
    if (typeof initialsColor === 'string') {
        initialsColorCode = initialsColor;
    }
    else {
        initialsColor = initialsColor !== undefined ? initialsColor : getInitialsColorFromName(text || primaryText);
        initialsColorCode = personaInitialsColorToHexCode(initialsColor);
    }
    return initialsColorCode;
}
exports.initialsColorPropToColorCode = initialsColorPropToColorCode;
//# sourceMappingURL=PersonaInitialsColor.js.map