"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.normalizeLogins = normalizeLogins;
exports.normalizeLoginListValues = normalizeLoginListValues;
exports.findMissingLogins = findMissingLogins;
function normalizeLogins(logins) {
    const seen = new Set();
    const normalized = [];
    for (const login of logins) {
        const trimmed = login.trim().replace(/^@+/, "");
        if (!trimmed) {
            continue;
        }
        const key = trimmed.toLowerCase();
        if (seen.has(key)) {
            continue;
        }
        seen.add(key);
        normalized.push(trimmed);
    }
    return normalized;
}
function normalizeLoginListValues(values) {
    return normalizeLogins(values.flatMap((value) => value.split(",")));
}
function findMissingLogins({ requestedLogins, existingLogins, excludedLogins = [], }) {
    const excludedKeys = new Set([
        ...normalizeLoginKeys(existingLogins),
        ...normalizeLoginKeys(excludedLogins),
    ]);
    return normalizeLogins(requestedLogins).filter((login) => !excludedKeys.has(login.toLowerCase()));
}
function normalizeLoginKeys(logins) {
    return normalizeLogins(logins.flatMap((login) => (login ? [login] : []))).map((login) => login.toLowerCase());
}
