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

export function RegisterPage() {
  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">Tạo tài khoản miễn phí</h1>
          <p className="text-sm text-slate-500 mt-1">Không cần xác nhận email — dùng ngay lập tức</p>
        </div>

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