"use client"; import { useState, useEffect } from "react"; import { usePathname } from "next/navigation"; import Image from "next/image"; interface PreloaderProps { children: React.ReactNode; } const Preloader = ({ children }: PreloaderProps) => { const [isLoading, setIsLoading] = useState(true); const [progress, setProgress] = useState(0); const [currentPath, setCurrentPath] = useState(""); const pathname = usePathname(); // Debug mode - set to true to see console logs const DEBUG = false; // Skip preloader for faster development/testing (set to true to disable preloader) const SKIP_PRELOADER = false; // Fast mode - set to true for even faster loading (200ms total) const FAST_MODE = true; useEffect(() => { // Only show preloader if path has changed or it's initial load if (currentPath !== pathname) { if (DEBUG) console.log('Preloader: Starting transition from', currentPath, 'to', pathname); setIsLoading(true); setProgress(0); // Simulate loading progress - faster and more responsive const progressInterval = setInterval(() => { setProgress((prev) => { if (prev >= 85) { clearInterval(progressInterval); return 85; } return prev + Math.random() * 25 + 10; // Faster progress increments }); }, 50); // Reduced interval from 100ms to 50ms for smoother animation // Complete loading much faster - adjust timing based on FAST_MODE const loadingDuration = FAST_MODE ? 200 : 400; const fadeOutDuration = FAST_MODE ? 50 : 100; const completeTimer = setTimeout(() => { setProgress(100); setTimeout(() => { if (DEBUG) console.log('Preloader: Transition complete'); setIsLoading(false); setCurrentPath(pathname); }, fadeOutDuration); }, loadingDuration); // Fallback: Force complete after reasonable time const fallbackDuration = FAST_MODE ? 800 : 1500; const fallbackTimer = setTimeout(() => { if (DEBUG) console.log('Preloader: Fallback triggered - force completing'); setIsLoading(false); setCurrentPath(pathname); setProgress(100); }, fallbackDuration); return () => { clearInterval(progressInterval); clearTimeout(completeTimer); clearTimeout(fallbackTimer); }; } }, [pathname, currentPath, DEBUG, FAST_MODE]); // Skip preloader entirely if SKIP_PRELOADER is true if (SKIP_PRELOADER) { return <>{children}>; } // Don't show preloader if not loading if (!isLoading) { return <>{children}>; } return ( <>