import { useEffect } from 'react'
import { useNavigate } from '@tanstack/react-router'
import { useUser } from '@/hooks/use-auth'
import { LoginForm } from './LoginForm'

export function LoginPage() {
  const user = useUser()
  const navigate = useNavigate()

  useEffect(() => {
    if (user) navigate({ to: '/' })
  }, [user, navigate])

  return (
    <div className="min-h-screen flex items-center justify-center p-4 bg-slate-50">
      <div className="w-full max-w-md">
        <div className="text-center mb-8">
          <div className="inline-flex items-center gap-2 mb-3">
            <span className="material-symbols-outlined text-blue-600 text-3xl">school</span>
            <span className="text-2xl font-bold text-slate-800">TOEIC Luyện thi</span>
          </div>
          <h1 className="text-xl font-semibold text-slate-700">Đăng nhập tài khoản</h1>
        </div>

        <div className="bg-white rounded-2xl shadow-sm border border-slate-200 p-6">
          <LoginForm
            onSuccess={() => navigate({ to: '/' })}
            onSwitchToRegister={() => navigate({ to: '/auth/register' })}
          />
        </div>
      </div>
    </div>
  )
}
