"use client";

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

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

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

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

      // settings فقط وقتی لاگین است prefetch شود
      if (isAuthenticated()) {
        router.prefetch("/settings");
      }
    }, 2000);

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

  return null;
}
