import { useState, useEffect } from "react"; // Import all images statically // import home1 from "../assets/home1.jpg"; // import home1Mobile from "../assets/home1-2.jpg"; // import home2 from "../assets/home2.jpg"; // import home2Mobile from "../assets/home2-2.jpg"; // import home3 from "../assets/home3.png"; // import home4 from "../assets/home4.png"; // // import home4Mobile from "../assets/home4-2.jpg"; // import home5 from "../assets/home5.png"; // import home6 from "../assets/home6.jpg"; // import home6Mobile from "../assets/home6-2.jpg"; // import home7 from "../assets/home7.jpg"; // import home7Mobile from "../assets/home7-2.jpg"; // import home8 from "../assets/home8.jpg"; // import home8Mobile from "../assets/home8-2.jpg"; // import home9 from "../assets/home9.jpg"; // import home10 from "../assets/home10.jpg"; // Services images // import gasStation from "../assets/Images/gasstation.jpg"; // List all critical images that need to be preloaded const imagesToPreload = [ // Home images // home1, // home1Mobile, // home2, // home2Mobile, // home3, // home4, // home4Mobile, // home5, // home6, // home6Mobile, // home7, // home7Mobile, // home8, // home8Mobile, // home9, // home10, // Services images // gasStation, ]; const ImagePreloader = ({ children }) => { const [imagesLoaded, setImagesLoaded] = useState(false); const [progress, setProgress] = useState(0); useEffect(() => { let loadedCount = 0; const totalImages = imagesToPreload.length; const preloadImages = async () => { try { const loadImage = (src) => { return new Promise((resolve, reject) => { const img = new Image(); img.src = src; img.onload = () => { loadedCount++; setProgress(Math.floor((loadedCount / totalImages) * 100)); resolve(); }; img.onerror = reject; }); }; await Promise.all(imagesToPreload.map(loadImage)); setImagesLoaded(true); } catch (error) { console.error("Failed to preload images:", error); // Continue anyway after a timeout setTimeout(() => setImagesLoaded(true), 3000); } }; preloadImages(); }, []); if (!imagesLoaded) { return (
{/* Animated background effect */}
{[...Array(20)].map((_, i) => (
))}
{/* Company logo or branding could go here */}
TPS
{/* 3D-style Fuel Tank */}
{/* Tank body with 3D effect */}
{/* Glass effect overlay */}
{/* Tank Cap with metallic effect */}
{/* Fuel Level with dynamic wave effect */}
{/* Animated wave effect at the top of fuel */}
{/* Bubbles with varied animations */} {[...Array(8)].map((_, i) => (
))}
{/* Tank level markings with glow effect */}
{[...Array(4)].map((_, i) => (
75 - i * 25 ? "0 1px 3px rgba(243,198,35,0.3)" : "none", }} >
))}
{/* Fuel Gauge with realistic dial */}
{/* Gauge markings */} {[...Array(9)].map((_, i) => { const rotation = -135 + i * 30; const isLarge = i % 2 === 0; return (
); })} {/* Gauge needle with smooth animation */}
{/* Center pin */}
{/* E and F indicators */}
E
F
{/* Progress indicator with animated glow */}

{progress}%

Filling your tank...

{/* Advanced animations */} {/* */}
); } return <>{children}; }; export default ImagePreloader;