// ─── K&N Elite — Login / OTP (unified light) ─── const { useState, useEffect } = React; function ScreenLogin({ onSuccess, prefillPhone }) { const { t } = useI18n(); const [step, setStep] = useState("phone"); const [phone, setPhone] = useState(prefillPhone || "+34 "); const [code, setCode] = useState(["", "", "", "", "", ""]); const [resend, setResend] = useState(60); useEffect(() => { if (step !== "code") return; const id = setInterval(() => setResend(r => Math.max(0, r - 1)), 1000); return () => clearInterval(id); }, [step]); const setDigit = (i, v) => { if (!/^\d?$/.test(v)) return; const arr = [...code]; arr[i] = v; setCode(arr); if (v && i < 5) { const next = document.getElementById("d-" + (i + 1)); next && next.focus(); } if (arr.every(x => x !== "")) setTimeout(() => onSuccess(phone), 400); }; return (
{t("login_sub")}

{t("login_title")}

{step === "phone" ? ( <>
{t("login_phone_label")}
setPhone(e.target.value)} autoFocus />
{t("login_or")}
) : ( <>
{t("login_code_label")}
{code.map((d, i) => ( setDigit(i, e.target.value)} maxLength={1} style={{ width: 54, height: 64, textAlign: "center", fontFamily: "var(--serif)", fontSize: 28, fontWeight: 400, background: "var(--paper)", border: "1px solid var(--ink-10)", transition: "all .25s var(--ease)", borderRadius: 2, }} onFocus={(e) => { e.target.style.borderColor = "var(--gold)"; e.target.style.boxShadow = "var(--sh-gold)"; }} onBlur={(e) => { e.target.style.borderColor = "var(--ink-10)"; e.target.style.boxShadow = "none"; }} /> ))}
{t("login_code_hint")}
{resend > 0 ? `${t("login_resend_in")} ${resend}s` : setResend(60)}>{t("login_resend")}}
{t("login_demo_note")}
)}
); } Object.assign(window, { ScreenLogin });