import { Navigate, Outlet } from "react-router-dom"
import { useAuthStore } from "@/store/authStore"

export function ProtectedRoute() {
  const isLoggedIn = useAuthStore((s) => !!s.token)
  if (!isLoggedIn) return <Navigate to="/login" replace />
  return <Outlet />
}

export function AdminRoute() {
  const isLoggedIn = useAuthStore((s) => !!s.token)
  const isAdmin = useAuthStore((s) => s.isAdmin())
  if (!isLoggedIn) return <Navigate to="/login" replace />
  if (!isAdmin) return <Navigate to="/books" replace />
  return <Outlet />
}
