/**
 * modules/auth/patternLogin.js — Patrón 3x3 como secuencia "1-2-3".
 */
(function (g) {
    g.modules = g.modules || {};
    g.modules.auth = g.modules.auth || {};

    var crypto = g.modules.core.crypto;

    function normalize(seq) {
        return String(seq || '')
            .replace(/[^1-9]/g, '')
            .split('')
            .filter(function (d, i, a) {
                return i === 0 || d !== a[i - 1];
            })
            .join('-');
    }

    g.modules.auth.patternLogin = {
        normalize: normalize,

        verify: async function (user, patternSeq) {
            if (!user || !user.patternHash) return false;
            var norm = normalize(patternSeq);
            var h = await crypto.hashSecret(norm, user.patternSalt);
            return crypto.timingSafeEqualB64(h, user.patternHash);
        },
    };
})(typeof window !== 'undefined' ? window : this);
