import React, { useState, useCallback, useMemo, useEffect, useRef } from 'react'; import { MessageCircle, Users, MapPin, Award } from 'lucide-react'; import { cn } from '@/lib/utils'; import { popularTrips } from '@/data/popularTrips'; import { weekendTrips } from '@/data/weekendTrips'; import { internationalTours } from '@/data/internationalTours'; import { honeymoonPackages } from '@/data/honeymoonPackages'; import { ladakhBikingTrips, ladakhSUVTrips } from '@/data/ladakhTrips'; import { offBeatTrips } from '@/data/offBeatTrips'; import BannerSearchBar from './banner/BannerSearchBar'; import StatsCounter from './banner/StatsCounter'; import ProgressiveImage from './ProgressiveImage'; import { useIsMobile } from '@/hooks/use-mobile'; import { enhancedPerformanceService } from '@/services/enhancedPerformanceService'; interface OptimizedBannerProps { onSearch: (query: string) => void; } const OptimizedBanner: React.FC = React.memo(({ onSearch }) => { const [isBannerVisible, setIsBannerVisible] = useState(true); const videoRef = useRef(null); const [hasUserInteracted, setHasUserInteracted] = useState(false); // Check banner visibility from localStorage useEffect(() => { const checkBannerVisibility = () => { const isDismissed = localStorage.getItem('winter-promo-dismissed-2024') === 'true'; setIsBannerVisible(!isDismissed); }; // Check initially checkBannerVisibility(); // Listen for localStorage changes window.addEventListener('storage', checkBannerVisibility); // Poll for changes (in case localStorage is updated in same tab) const interval = setInterval(checkBannerVisibility, 500); return () => { window.removeEventListener('storage', checkBannerVisibility); clearInterval(interval); }; }, []); // Handle user interaction for autoplay policy compliance useEffect(() => { const handleUserInteraction = () => { setHasUserInteracted(true); if (videoRef.current) { videoRef.current.play().catch(() => { console.log('Video play failed even after user interaction'); }); } }; // Add interaction listeners document.addEventListener('click', handleUserInteraction, { once: true }); document.addEventListener('touchstart', handleUserInteraction, { once: true }); return () => { document.removeEventListener('click', handleUserInteraction); document.removeEventListener('touchstart', handleUserInteraction); }; }, []); // Video intersection observer for play when visible useEffect(() => { const video = videoRef.current; if (!video) return; const observer = new IntersectionObserver( (entries) => { entries.forEach((entry) => { if (entry.isIntersecting && hasUserInteracted) { video.play().catch(() => { console.log('Video autoplay prevented'); }); } else if (!entry.isIntersecting) { video.pause(); } }); }, { threshold: 0.5 } ); observer.observe(video); return () => observer.disconnect(); }, [hasUserInteracted]); // const [currentImageIndex, setCurrentImageIndex] = useState(0); // const isMobile = useIsMobile(); // Memoize trip data aggregation const allTrips = useMemo(() => [ ...popularTrips, ...weekendTrips, ...internationalTours, ...honeymoonPackages, ...ladakhBikingTrips, ...ladakhSUVTrips, ...offBeatTrips ], []); const isMobile = useIsMobile(); // Travel-themed video sources for better compatibility // const videoSources = useMemo(() => [ // '/images/bggirlhero.webm', // '/images/bgindgirl.mp4' // ], []); // Handle video events const handleVideoLoad = useCallback(() => { console.log('Video loaded successfully'); }, []); const handleVideoError = useCallback(() => { console.log('Video failed to load, using fallback'); }, []); // // Optimized banner images with priority loading // const bannerImages = useMemo(() => [ // 'https://images.unsplash.com/photo-1493246507139-91e8fad9978e?auto=format&fit=crop&w=2000&q=90&fm=webp', // 'https://images.unsplash.com/photo-1571401835393-8c5f35328320?auto=format&fit=crop&w=2000&q=90&fm=webp', // 'https://images.unsplash.com/photo-1506905925346-21bda4d32df4?auto=format&fit=crop&w=2000&q=90&fm=webp', // 'https://images.unsplash.com/photo-1506197603052-3cc9c3a201bd?auto=format&fit=crop&w=2000&q=90&fm=webp' // ], []); // // Preload next images when current changes // React.useEffect(() => { // enhancedPerformanceService.preloadNextImages(bannerImages, currentImageIndex); // }, [currentImageIndex, bannerImages]); // // Optimized image rotation // React.useEffect(() => { // const interval = setInterval(() => { // setCurrentImageIndex((prevIndex) => (prevIndex + 1) % bannerImages.length); // }, 5000); // return () => clearInterval(interval); // }, [bannerImages.length]); // const handleImageChange = useCallback((index: number) => { // setCurrentImageIndex(index); // }, []); // return ( //
// {/* Optimized Image Slider */} //
// {bannerImages.map((image, index) => ( //
// //
// ))} // {/* Gradient Overlay */} //
//
// {/* Content */} //
//

// Discover Incredible Destinations //

// // {/* Stats Counters */} //
//
//
// // // // //
//
//
//
// {/* Image Navigation Dots */} //
// {bannerImages.map((_, index) => ( //
//
// ); // }); // OptimizedBanner.displayName = 'OptimizedBanner'; // export default OptimizedBanner; return ( // Frame-like structure with responsive spacing - mobile optimized // Frame-like structure with responsive spacing - mobile optimized
{/* Video Background */}
{/* Gradient Overlay */}
{/* Content */}
{/* Main Content - Centered */}
{/* Brand Title */}

#GoFeelIt

{/* Tagline */}


{/* Search Bar - Hidden on Mobile */}
{/* Stats Counters - Positioned differently on mobile vs desktop */}
); }); OptimizedBanner.displayName = 'OptimizedBanner'; export default OptimizedBanner;