(function(){ if (window.__AUTH_HOTFIX__) return; window.__AUTH_HOTFIX__ = 1; function show(msg, type){ try { showAuthMsg(msg, type); } catch(e){ console.log("[auth]", type||"ok", msg); } } async function post(url, payload){ if (typeof window.api === 'function'){ return window.api("POST", url, payload); } const r = await fetch(url, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(payload), credentials: "include", }); if (!r.ok) { let t = ""; try { t = await r.text(); } catch(_){} throw new Error(t || ("HTTP " + r.status)); } try { return await r.json(); } catch(_) { return null; } } async function requestAccess(ev){ if (ev && ev.preventDefault) ev.preventDefault(); const btn = document.getElementById("btnRequestAccess") || document.querySelector("[data-req-btn],[data-action='request-access']"); const chk = document.getElementById("consentChk") || document.querySelector("input[type=checkbox][name*='consent']"); const emailInput = document.getElementById("emailInput") || document.querySelector("input[type=email], input[name*=email i], input[name*=Email i]"); try{ if(!chk || !chk.checked){ show("Поставьте галочку согласия перед отправкой заявки","warn"); return; } const email = (emailInput && emailInput.value || "").trim(); if(!email){ show("Укажите email для заявки","warn"); return; } await post("/public/registration_request", { email, consent: true, source: "v_2_auth" }); show("Заявка отправлена. Мы свяжемся по email.","ok"); }catch(err){ show((err && (err.detail || err.message)) || "Не удалось отправить заявку","err"); } } window.__authRequestAccess = requestAccess; function arm(){ const btn = document.getElementById("btnRequestAccess") || document.querySelector("[data-req-btn],[data-action='request-access']"); if(!btn) return; try { btn.setAttribute("type","button"); } catch(_){} // Снимаем предыдущих слушателей, если были (через клон) try { btn.replaceWith(btn.cloneNode(true)); } catch(_) {} const b = document.getElementById("btnRequestAccess") || document.querySelector("[data-req-btn],[data-action='request-access']"); if(!b) return; b.addEventListener("click", requestAccess, { capture: true }); } // Навешиваем при готовности DOM и сразу (если всё уже на месте) document.addEventListener("DOMContentLoaded", arm); arm(); // Доп. страховка: если кликнули, но обработчик вдруг ещё не висит — дозаводим и пытаемся снова document.addEventListener("click", function(ev){ const t = ev.target; if (!t) return; if (t.id === "btnRequestAccess" || t.matches?.("[data-req-btn],[data-action='request-access']")) { if (typeof t.onclick !== "function") arm(); } }, true); })();