import { Navigate, Outlet } from 'react-router-dom'
import { useAuth } from '../auth/AuthContext'
import { isAdminMember } from '../lib/memberRole'

export function AdminRoute() {
  const { member, loading } = useAuth()

  if (loading) {
    return (
      <div className="flex min-h-[12rem] items-center justify-center text-muted">
        載入中…
      </div>
    )
  }

  if (!isAdminMember(member)) {
    return <Navigate to="/" replace />
  }

  return <Outlet />
}