import React from "react";
import { Navigate, useLocation } from "react-router-dom";

export default function ProtectedRoute({ children }) {
  const isAdmin = sessionStorage.getItem("admin"); // session-based login
  const location = useLocation(); // current path

  if (!isAdmin) {
    // redirect to login and remember attempted page
    return <Navigate to="/admin-login" replace state={{ from: location }} />;
  }

  return children;
}
