'use client'

import { useEffect } from 'react'
import { useRouter } from 'next/navigation'

export default function AuthRedirectPage() {
  const router = useRouter()

  useEffect(() => {
    const hash = window.location.hash
    const params = new URLSearchParams(hash.replace(/^#/, ''))
    const token = params.get('token')
    const next = params.get('next') || '/dashboard'

    if (token) {
      localStorage.setItem('admin_token', token)
      // Clear the token from the URL
      window.history.replaceState(null, '', window.location.pathname)
    }

    router.replace(next)
  }, [router])

  return (
    <div className="flex min-h-screen items-center justify-center bg-zinc-950">
      <p className="text-sm text-zinc-400">Redirecting to admin dashboard…</p>
    </div>
  )
}
