// screens-auth.jsx — Splash (loading), first-visit number detection, SMS OTP // Set to a valid file path (e.g. "assets/telecel-logo-white.svg") once a logo with real artwork is provided. const TELECEL_LOGO_WHITE = "assets/telecel-logo-white.png"; function SplashLogo() { if (TELECEL_LOGO_WHITE) return Telecel — Conectando Energias; return ; } /* ─────────────────────────── SPLASH / LOADING ─────────────────────────── */ function ScreenSplash({ go }) { const [p, setP] = useState(0); useEffect(() => { const iv = setInterval(() => setP(v => Math.min(100, v + 4)), 80); const t = setTimeout(() => go(localStorage.getItem(FIRST_VISIT_KEY) ? "home" : "login"), 2300); return () => { clearInterval(iv); clearTimeout(t); }; }, []); return (
A carregar…
); } /* ─────────────────────────── FIRST VISIT: NUMBER DETECTION ─────────────────────────── */ function ScreenLogin({ go, user }) { const [state, setState] = useState("detecting"); // detecting | detected | manual const [manual, setManual] = useState(""); useEffect(() => { const t = setTimeout(() => setState(s => s === "detecting" ? "detected" : s), 1500); return () => clearTimeout(t); }, []); const detected = user.phone; const canContinue = state === "detected" || (state === "manual" && isTelecelNumber(manual)); const phone = state === "manual" ? formatTelecel(manual) : detected; return ( <>

Bem-vindo à Telecel.

Confirmamos o teu número uma única vez. Nas próximas visitas entras diretamente.

{state !== "manual" ? (
{state === "detecting" ?
: null} {state === "detecting" ? : }
{state === "detecting" ? "A detetar o teu número…" : "Número detetado automaticamente"}
{state === "detecting" ?
:
{detected}
}
Via rede móvel Telecel · sem precisares de escrever
) : (
O teu número Telecel
)}
); } /* ─────────────────────────── OTP ─────────────────────────── */ function ScreenOtp({ go, args, user }) { const phone = args?.phone || user.phone; const [digits, setDigits] = useState(["", "", "", ""]); const [active, setActive] = useState(0); const [seconds, setSeconds] = useState(38); const [verified, setVerified] = useState(false); useEffect(() => { if (seconds <= 0) return; const t = setTimeout(() => setSeconds(seconds - 1), 1000); return () => clearTimeout(t); }, [seconds]); const finish = () => { localStorage.setItem(FIRST_VISIT_KEY, "1"); go("home"); }; useEffect(() => { const code = "4729"; const stops = [0, 1, 2, 3].map(i => setTimeout(() => { setDigits(d => { const c = [...d]; c[i] = code[i]; return c; }); setActive(i + 1); }, 900 + i * 350)); stops.push(setTimeout(() => setVerified(true), 2500)); stops.push(setTimeout(finish, 3300)); return () => stops.forEach(clearTimeout); }, []); return ( <>
{verified ? : }

{verified ? "Número verificado!" : "Código enviado por SMS."}

Enviámos um código de 4 dígitos para {phone}. O código é lido automaticamente.

{digits.map((d, i) => (
{d || (active === i ? | : "")}
))}
{seconds > 0 ? <>Reenviar SMS em 0:{String(seconds).padStart(2, "0")} : }
); } Object.assign(window, { ScreenSplash, ScreenLogin, ScreenOtp });