'use client'

import { Suspense, useEffect } from 'react'
import { useRouter, useSearchParams } from 'next/navigation'
import { safeInternalHref } from '@/lib/navigation'

function AdminLoginRedirectContent() {
  const router = useRouter()
  const searchParams = useSearchParams()
  const redirect = safeInternalHref(searchParams.get('redirect') || '/admin', '/admin')

  useEffect(() => {
    router.replace(`/login?redirect=${encodeURIComponent(redirect)}`)
  }, [redirect, router])

  return (
    <section className="grid min-h-[calc(100vh-70px)] place-items-center bg-bg px-6">
      <div className="text-sm font-extrabold text-muted">正在打开统一登录入口...</div>
    </section>
  )
}

export default function AdminLoginRedirectPage() {
  return (
    <Suspense fallback={<section className="grid min-h-[calc(100vh-70px)] place-items-center bg-bg px-6"><div className="text-sm font-extrabold text-muted">正在打开统一登录入口...</div></section>}>
      <AdminLoginRedirectContent />
    </Suspense>
  )
}
