'use client'; import React, { useEffect, useState } from 'react'; import { motion, AnimatePresence } from 'framer-motion'; const PRELOAD_VIDEOS = [ '/assets/videos/web/hero-bohrung.mp4' ]; export function InitialLoader({ shouldShowLoader = true }: { shouldShowLoader?: boolean }) { const [isLoading, setIsLoading] = useState(shouldShowLoader); useEffect(() => { if (!shouldShowLoader) return; // Fallback Timeout (4 Sekunden), falls Videos hängen const timeout = setTimeout(() => { finishLoading(); }, 4000); let videosLoaded = 0; const checkAllLoaded = () => { videosLoaded++; if (videosLoaded === PRELOAD_VIDEOS.length) { clearTimeout(timeout); // Kleine Verzögerung für die smootheness setTimeout(finishLoading, 800); } }; PRELOAD_VIDEOS.forEach((src) => { const video = document.createElement('video'); video.preload = 'auto'; video.oncanplaythrough = checkAllLoaded; video.onerror = checkAllLoaded; // bei Fehler trotzdem weitermachen video.src = src; video.load(); }); // Cleanup return () => clearTimeout(timeout); }, [shouldShowLoader]); const finishLoading = () => { // Set a session cookie so the server knows not to render the loader again document.cookie = "etib_initial_load=true; path=/; samesite=lax"; setIsLoading(false); }; // Wenn wir serverseitig rendern und es nicht zeigen sollen, return null if (!shouldShowLoader) return null; return ( {isLoading && ( {/* E-TIB Premium Glow */}
{/* Minimalistisches Logo oder Loader */}
E-TIB
Loading Infrastructure
)} ); }