"use client"; import { useActionState } from "react"; import Link from "next/link"; import { Icons } from "@/components/icons"; import type { FormState } from "./auth-actions"; type Action = (prev: FormState, data: FormData) => Promise; export function AuthForm({ mode, action, next = "/", }: { mode: "login" | "register"; action: Action; next?: string; }) { const [state, formAction, pending] = useActionState( action, {}, ); const isLogin = mode === "login"; const title = isLogin ? "Đăng nhập" : "Tạo tài khoản"; const subtitle = isLogin ? "Tiếp tục với địa điểm đã lưu của bạn" : "Bắt đầu lưu địa điểm cùng nhóm nhỏ"; const cta = isLogin ? "Đăng nhập" : "Đăng ký"; const switchPrompt = isLogin ? "Chưa có tài khoản?" : "Đã có tài khoản?"; const switchBase = isLogin ? "/register" : "/login"; const switchHref = next && next !== "/" ? `${switchBase}?next=${encodeURIComponent(next)}` : switchBase; const switchLabel = isLogin ? "Đăng ký" : "Đăng nhập"; return (

{title}

{subtitle}

{!isLogin && ( <> )} {isLogin ? ( ) : ( )} {state.error && (
{state.error}
)}
{switchPrompt}{" "} {switchLabel}
); } function Field({ label, children, }: { label: string; children: React.ReactNode; }) { return ( ); }