"use client"; import { motion } from "framer-motion"; import { Mail } from "lucide-react"; import { useState } from "react"; import { ScreenHeader, ScreenShell } from "@/components/online/ScreenHeader"; import { useSessionStore } from "@/lib/session-store"; import { useUIStore } from "@/lib/ui-store"; import { useI18n } from "@/lib/i18n"; export function AuthScreen() { const { t } = useI18n(); const go = useUIStore((s) => s.go); const done = () => go("online"); return ( {t("auth.subtitle")} {/* Active method: phone OTP */} {/* Coming soon (until email SMTP / Google are configured) */} {t("auth.otherSoon")} } label={t("auth.email")} soon={t("common.soon")} /> } label={t("auth.google")} soon={t("common.soon")} /> ); } function SoonButton({ icon, label, soon, }: { icon: React.ReactNode; label: string; soon: string; }) { return ( {icon} {label} {soon} ); } function PhoneForm({ onDone }: { onDone: () => void }) { const { t } = useI18n(); const requestOtp = useSessionStore((s) => s.requestOtp); const verifyOtp = useSessionStore((s) => s.verifyOtp); const [phone, setPhone] = useState(""); const [code, setCode] = useState(""); const [sent, setSent] = useState(false); const [devCode, setDevCode] = useState(null); const [busy, setBusy] = useState(false); const [error, setError] = useState(""); const send = async () => { if (phone.trim().length < 10) { setError(t("auth.invalidPhone")); return; } setBusy(true); setError(""); try { const res = await requestOtp(phone.trim()); setDevCode(res.devCode ?? null); setSent(true); // advance to the code step regardless of dev/prod } catch { setError(t("auth.sendFailed")); } finally { setBusy(false); } }; const verify = async () => { try { await verifyOtp(phone.trim(), code.trim()); onDone(); } catch { setError(t("auth.invalidCode")); } }; return ( {t("auth.phoneLabel")} setPhone(e.target.value)} placeholder={t("auth.phonePlaceholder")} className="w-full rounded-xl bg-navy-900/70 gold-border px-4 py-3 text-cream text-center tracking-wider outline-none focus:ring-2 focus:ring-gold-500/40" /> {!sent ? ( <> {busy ? t("auth.sending") : t("auth.sendCode")} {error && {error}} > ) : ( {devCode ? ( {t("auth.devCode", { code: devCode })} ) : ( {t("auth.codeSent")} )} {t("auth.codeLabel")} setCode(e.target.value)} placeholder={t("auth.codePlaceholder")} maxLength={6} className="w-full rounded-xl bg-navy-900/70 gold-border px-4 py-3 text-cream text-center text-xl tracking-[0.5em] outline-none focus:ring-2 focus:ring-gold-500/40" /> {error && {error}} {t("auth.verify")} { setSent(false); setCode(""); setError(""); }} className="w-full text-center text-xs text-cream/45 hover:text-cream" > {t("auth.changeNumber")} )} ); } function GoogleIcon() { return ( ); }
{t("auth.subtitle")}
{t("auth.otherSoon")}
{error}
{t("auth.codeSent")}