'use client' import React, { lazy, Suspense, useEffect, useState, useRef } from 'react' import { ProductGridSkeleton } from '@/components/ui/LazyLoader' // Helper to detect mobile devices const isMobile = () => { if (typeof window === 'undefined') return false return window.innerWidth <= 768 || /Android|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) } // More aggressive lazy loading for mobile devices const HeroSection = lazy(() => import('@/components/sections/HeroSection')) const AboutSection = lazy(() => import('@/components/sections/AboutSection')) const KashminaSection = lazy(() => isMobile() ? import('@/components/sections/KashminaSection').then(module => ({ default: module.default })) : import('@/components/sections/KashminaSection') ) const ManufacturingSection = lazy(() => import('@/components/sections/ManufacturingSection').then(module => ({ default: module.default })) ) const StatsSection = lazy(() => import('@/components/sections/StatsSection').then(module => ({ default: module.default })) ) const CertificationsSection = lazy(() => import('@/components/sections/CertificationsSection').then(module => ({ default: module.default })) ) const NewsSection = lazy(() => import('@/components/sections/NewsSection').then(module => ({ default: module.default })) ) const OurValues = lazy(() => import('@/components/sections/OurValues').then(module => ({ default: module.default })) ) // Intersection Observer for better mobile performance const useIntersectionObserver = (ref: React.RefObject, threshold = 0.1) => { const [isIntersecting, setIsIntersecting] = useState(false) useEffect(() => { const current = ref.current if (!current) return const observer = new IntersectionObserver( ([entry]) => { if (entry.isIntersecting) { setIsIntersecting(true) observer.unobserve(current) } }, { threshold, rootMargin: '100px' } ) observer.observe(current) return () => observer.disconnect() }, [ref, threshold]) return isIntersecting } // Mobile-optimized lazy wrapper function MobileLazyWrapper({ children, fallback, className = '', priority = false }: { children: React.ReactNode fallback: React.ReactNode className?: string priority?: boolean }) { const ref = useRef(null) const isVisible = useIntersectionObserver(ref as React.RefObject) const [shouldRender, setShouldRender] = useState(priority) useEffect(() => { if (isVisible || priority) { // Add small delay for mobile to prevent blocking const timer = setTimeout(() => setShouldRender(true), isMobile() ? 50 : 0) return () => clearTimeout(timer) } }, [isVisible, priority]) return (
{shouldRender ? ( {children} ) : ( fallback )}
) } // Optimized lazy components with better mobile performance export function MobileOptimizedLazyHeroSection() { const fallback = (
) return ( ) } export function MobileOptimizedLazyAboutSection() { const fallback = (
) return ( ) } export function MobileOptimizedLazyKashminaSection() { const fallback = (
{Array.from({ length: 4 }).map((_, i) => (
))}
) return ( ) } export function MobileOptimizedLazyManufacturingSection() { const fallback = (
{Array.from({ length: 3 }).map((_, i) => (
))}
) return ( ) } export function MobileOptimizedLazyStatsSection() { const fallback = (
{Array.from({ length: 4 }).map((_, i) => (
))}
) return ( ) } export function MobileOptimizedLazyCertificationsSection() { const fallback = (
{Array.from({ length: 4 }).map((_, i) => (
))}
) return ( ) } export function MobileOptimizedLazyNewsSection() { const fallback = (
{Array.from({ length: 3 }).map((_, i) => (
))}
) return ( ) } export function MobileOptimizedLazyOurValues() { const fallback = (
{Array.from({ length: 4 }).map((_, i) => (
))}
) return ( ) }