"use client";

import { useEffect, useState } from "react";

/**
 * Returns true when a valid DriveHub admin session token exists in sessionStorage.
 * Hydration-safe: always false on the server, resolves on the client.
 */
export function useIsAdmin(): boolean {
  const [isAdmin, setIsAdmin] = useState(false);

  useEffect(() => {
    try {
      const token = sessionStorage.getItem("drivehub_admin_token");
      setIsAdmin(Boolean(token));
    } catch {
      // sessionStorage unavailable (SSR / restricted context)
      setIsAdmin(false);
    }
  }, []);

  return isAdmin;
}
