"use client";

import { useEffect } from "react";
import { useRouter } from "next/navigation";
import { isAuthenticated } from "@/lib/auth/session";

const PUBLIC_ROUTES = ["/", "/academy", "/billboards", "/explore", "/register"];

export default function BackgroundPrefetch() {
  const router = useRouter();

  useEffect(() => {
    const t = window.setTimeout(() => {
      PUBLIC_ROUTES.forEach((route) => router.prefetch(route));

      if (isAuthenticated()) {
        router.prefetch("/settings");
        router.prefetch("/settings/profile");
      }
    }, 1500);

    return () => window.clearTimeout(t);
  }, [router]);

  return null;
}
