/* E-posta kontrolü: "gmail.co", "hotmial.com", "ali@gmail" gibi eksik/yanlış adresler kabul edilmez, öneri sunulmaz; kullanıcıdan adresi tam yazması istenir. Kurallar sunucudan gelir (store/validation.py EMAIL_RULES → #email-rules). */ (function () { const source = document.getElementById('email-rules'); if (!source) return; let rules; try { rules = JSON.parse(source.textContent || '{}'); } catch (e) { return; } const domains = rules.domains || {}; const strict = rules.strict || {}; const labels = new Set(rules.labels || []); const MESSAGE = 'E-posta adresini eksiksiz ve doğru yaz (örn. isim@gmail.com).'; function isWrong(value) { const at = value.lastIndexOf('@'); if (at < 1) return true; const domain = value.slice(at + 1).toLowerCase(); // Uzantısı olmayan (ali@gmail) ya da yarım kalan (ali@gmail.) adresler eksik sayılır. if (!/^[a-z0-9-]+(\.[a-z0-9-]+)*\.[a-z]{2,}$/.test(domain)) return true; const label = domain.split('.')[0]; if (domain in domains || labels.has(label)) return true; return label in strict && domain !== strict[label]; } function hintFor(input) { let hint = input.__emailHint; if (!hint) { hint = document.createElement('p'); hint.className = 'email-hint text-xs mt-1.5 text-red-600'; hint.setAttribute('role', 'alert'); hint.textContent = MESSAGE; hint.hidden = true; // Kutu bir sarmalayıcı içindeyse (ikonlu alanlar) uyarıyı sarmalayıcının altına koy. const anchor = input.closest('.auth-field') || input; anchor.insertAdjacentElement('afterend', hint); input.__emailHint = hint; } return hint; } // show=false: yazarken uyarıyı yalnızca düzeldiğinde kaldır, yeni uyarı gösterme. function check(input, show) { const value = input.value.trim(); const wrong = value !== '' && isWrong(value); input.setCustomValidity(wrong ? MESSAGE : ''); const hint = hintFor(input); if (!wrong) hint.hidden = true; else if (show) hint.hidden = false; } const isEmail = (el) => el.matches && el.matches('input[type="email"]'); document.addEventListener('input', (event) => { if (isEmail(event.target)) check(event.target, false); }); document.addEventListener('focusout', (event) => { if (isEmail(event.target)) check(event.target, true); }); document.addEventListener('invalid', (event) => { if (isEmail(event.target)) check(event.target, true); }, true); document.querySelectorAll('input[type="email"]').forEach((input) => { if (input.value) check(input, true); }); })();