'use client'; import { zodResolver } from '@hookform/resolvers/zod'; import { ChevronDown, Loader2, Sparkles } from 'lucide-react'; import { useRouter, useSearchParams } from 'next/navigation'; import { useTranslations } from 'next-intl'; import { useState } from 'react'; import { useForm } from 'react-hook-form'; import { OAuthButtons } from '@/components/auth/oauth-buttons'; import { Badge } from '@/components/ui/badge'; import { Button } from '@/components/ui/button'; import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from '@/components/ui/card'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; import { Link } from '@/i18n/navigation'; import { useAuthStore } from '@/lib/auth-store'; import { loginSchema, type LoginFormData } from '@/lib/validations/auth'; const DEMO_PASSWORD = 'Velik@2026'; const DEMO_ACCOUNTS: { phone: string; name: string; role: 'ADMIN' | 'AGENT' | 'SELLER' | 'BUYER'; badgeClass: string }[] = [ { phone: '+84876677771', name: 'Hồ Ngọc Hải', role: 'ADMIN', badgeClass: 'bg-red-500/10 text-red-600 border-red-500/20' }, { phone: '+84900000002', name: 'Nguyễn Văn An', role: 'AGENT', badgeClass: 'bg-blue-500/10 text-blue-600 border-blue-500/20' }, { phone: '+84900000005', name: 'Phạm Đức Dũng', role: 'SELLER', badgeClass: 'bg-amber-500/10 text-amber-600 border-amber-500/20' }, { phone: '+84900000004', name: 'Lê Minh Cường', role: 'BUYER', badgeClass: 'bg-emerald-500/10 text-emerald-600 border-emerald-500/20' }, ]; export default function LoginPage() { const router = useRouter(); const searchParams = useSearchParams(); const { login, isLoading, error, clearError } = useAuthStore(); const [showPassword, setShowPassword] = useState(false); const [demoOpen, setDemoOpen] = useState(true); const t = useTranslations('auth'); const oauthError = searchParams.get('error'); const oauthErrorMessage = oauthError ? t(`oauthErrors.${oauthError}` as Parameters[0]) ?? t('oauthErrors.default') : null; const { register, handleSubmit, setValue, formState: { errors }, } = useForm({ resolver: zodResolver(loginSchema), }); const fillDemoAccount = (phone: string) => { setValue('phone', phone, { shouldValidate: true }); setValue('password', DEMO_PASSWORD, { shouldValidate: true }); clearError(); }; const onSubmit = async (data: LoginFormData) => { try { await login(data); router.push('/'); } catch { // Error is handled by the store } }; return ( {t('loginTitle')} {t('loginDescription')} {/* Demo accounts panel — MVP only */}
{demoOpen && (

{t('demoAccountsHint')} {DEMO_PASSWORD}

    {DEMO_ACCOUNTS.map((acc) => (
  • ))}
)}
{oauthErrorMessage && (
{oauthErrorMessage}
)} {error && (
{error}
)}
{errors.phone && ( )}
{errors.password && ( )}
{t('orLoginWith')}

{t('noAccount')}{' '} {t('registerLink')}

); }