"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.convertNameToInitials = void 0;
/** A utility function that can be used with MessagingAvatar to convert a name into initials. */
function convertNameToInitials(name) {
    if (!name.trim()) {
        return "";
    }
    var nameSegments = name
        .split("-")
        .map(function (seg) { return seg.trim(); })
        .join(" ")
        .split(" ")
        .filter(function (seg) { return seg; });
    // Special handling if someone only types in one segment.
    if (nameSegments.length === 1) {
        // If someone is already writing their own initials or goes by a short, all-caps
        //  mononym (e.g. JR Smith of NBA fame is often simply "JR"), then don't mangle it.
        if (name === name.toUpperCase() && name.length <= 3) {
            return name;
        }
        return name.substring(0, 1).toUpperCase();
    }
    var prefixExclusions = ["ms", "miss", "mr", "mrs", "mx", "dr"];
    var suffixExclusions = [
        "jr",
        "sr",
        "i",
        "ii",
        "iii",
        "iv",
        "v",
        "vi",
        "vii",
        "viii",
        "ix",
        "x",
    ];
    // We don't want to exclude "Ron Valentine" putting in "Ron V" - the "V" is an initial.
    if (nameSegments.length > 2) {
        var lastSeg = nameSegments[nameSegments.length - 1]
            .toLowerCase()
            .split("")
            .filter(function (char) { return char !== "."; })
            .join("");
        if (suffixExclusions.includes(lastSeg)) {
            nameSegments.splice(nameSegments.length - 1, 1);
        }
    }
    var firstSeg = nameSegments[0]
        .toLowerCase()
        .split("")
        .filter(function (char) { return char !== "."; })
        .join("");
    if (prefixExclusions.includes(firstSeg)) {
        nameSegments.splice(0, 1);
    }
    // Max of three initials.
    if (nameSegments.length > 3) {
        nameSegments.splice(3);
    }
    return nameSegments
        .map(function (_name) { return _name.substring(0, 1); })
        .map(function (initial) { return initial.toUpperCase(); })
        .join("");
}
exports.convertNameToInitials = convertNameToInitials;
