import { Building2, CheckCircle2, Eye, EyeOff, UserRound } from "lucide-react"; import { useState, type FormEvent } from "react"; import { Link, useNavigate, useSearchParams } from "react-router-dom"; import { LangSwitch, ThemeSwitch } from "../components/Shell"; import { Button, ErrorNote, Field, Input, Logo, Waveform } from "../components/ui"; import { api } from "../lib/api"; import { useAuth } from "../lib/auth"; import { useI18n } from "../lib/i18n"; type Kind = "candidate" | "company"; /** Brand panel shown beside the sign-in and sign-up forms on wide screens. */ function SidePanel({ kind, mode }: { kind: Kind; mode: "signin" | "signup" }) { const { t } = useI18n(); const points = kind === "company" && mode === "signup" ? [t("side_c1"), t("side_c2"), t("side_c3")] : [t("side_p1"), t("side_p2"), t("side_p3")]; return ( ); } export default function Auth({ mode }: { mode: "signin" | "signup" }) { const { t } = useI18n(); const { signIn, signUp, signInWithGoogle, resetPassword, config, refresh } = useAuth(); const [params] = useSearchParams(); const nav = useNavigate(); const next = params.get("next"); const [kind, setKind] = useState(params.get("as") === "company" ? "company" : "candidate"); const [email, setEmail] = useState(""); const [password, setPassword] = useState(""); const [showPw, setShowPw] = useState(false); const [name, setName] = useState(""); const [company, setCompany] = useState(""); const [busy, setBusy] = useState(false); const [error, setError] = useState(null); const [notice, setNotice] = useState(null); const qs = (extra: Record = {}) => { const p = new URLSearchParams({ ...(next ? { next } : {}), ...extra }); const s = p.toString(); return s ? `?${s}` : ""; }; const submit = async (e: FormEvent) => { e.preventDefault(); setBusy(true); setError(null); try { if (mode === "signin") { await signIn(email, password); nav(next || "/app"); return; } const r = await signUp(email, password, name); if (r.needsConfirmation) { setNotice(t("check_email")); return; } if (kind === "company") { await api.post("/companies", { name: company.trim() }); await refresh(); nav("/app"); } else { await api.patch("/me", { role: "candidate" }).catch(() => undefined); await refresh(); nav(next || "/app"); } } catch (err: any) { setError(err?.message || t("error_generic")); } finally { setBusy(false); } }; const forgot = async () => { if (!email) { setError(t("forgot_need_email")); return; } try { await resetPassword(email); setNotice(t("reset_sent")); } catch (err: any) { setError(err?.message || t("error_generic")); } }; const tab = (to: "signin" | "signup", label: string) => ( {label} ); const kindCard = (k: Kind, Icon: typeof UserRound, title: string, desc: string) => ( ); const disabled = config && !config.enabled; return (
{tab("signin", t("sign_in"))} {tab("signup", t("sign_up"))}

{mode === "signin" ? t("auth_signin_title") : t("auth_signup_title")}

{mode === "signin" ? t("auth_signin_sub") : t("auth_signup_sub")}

{disabled ? (

{t("accounts_soon")}

{t("open_demo")}
) : notice ? (

{notice}

) : (
{mode === "signup" && (
{t("account_type")}
{kindCard("candidate", UserRound, t("kind_candidate"), t("kind_candidate_d"))} {kindCard("company", Building2, t("kind_company"), t("kind_company_d"))}
)} {config?.supabase_url && config.providers?.google && ( <>
{t("or")}
)} {mode === "signup" && ( setName(e.target.value)} required autoComplete="name" /> )} {mode === "signup" && kind === "company" && ( setCompany(e.target.value)} required minLength={2} autoComplete="organization" /> )} setEmail(e.target.value)} required autoComplete="email" dir="ltr" />
{mode === "signin" && config?.supabase_url && ( )}
setPassword(e.target.value)} required minLength={mode === "signup" ? 8 : 1} autoComplete={mode === "signup" ? "new-password" : "current-password"} dir="ltr" className="pe-11" />
{mode === "signup" && {t("password_hint")}}
{error && {error}}
)}

{mode === "signin" ? t("no_account") : t("have_account")}{" "} {mode === "signin" ? t("sign_up") : t("sign_in")}

); }