"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseMentionedUsers = parseMentionedUsers;
const constants_1 = require("../../../constants");
const MENTION_ATTRIBUTE_AND_VALUE_PATTERN = new RegExp(`${constants_1.MENTION_ATTRIBUTE}=('|")[\\w@\\.-]+('|")`, "g");
const MENTION_ATTRIBUTE_PATTERN = new RegExp(`${constants_1.MENTION_ATTRIBUTE}=`, "g");
const NON_WORDS_PATTERN = new RegExp("[^\\w@\\.-]", "g");
/**
 * Parses mentioned users
 * @param text A string to parse mentioned users from
 * @returns A unique collection of usernames parsed from the provided text
 */
function parseMentionedUsers(text = "") {
    const toReplaced = (input, pattern) => input.replace(pattern, "");
    const toMentionedUsers = (acc, match) => {
        const username = [MENTION_ATTRIBUTE_PATTERN, NON_WORDS_PATTERN].reduce(toReplaced, match);
        return acc.indexOf(username) < 0 ? [...acc, username] : acc;
    };
    const matches = text.match(MENTION_ATTRIBUTE_AND_VALUE_PATTERN) || [];
    return matches.reduce(toMentionedUsers, []);
}
//# sourceMappingURL=parse-mentioned-users.js.map