'use client' import { useState, useEffect, useMemo } from 'react' import Image from 'next/image' import Link from 'next/link' import { motion, AnimatePresence } from 'framer-motion' import { ChevronLeft, ChevronRight, Wheat } from 'lucide-react' import { Button } from '@/components/ui/button' interface Banner { id: number title: string subtitle: string description: string image: string cta: string ctaLink?: string bgColor?: string } interface FeatureCard { icon: any title: string description: string link: string color: string } export default function HeroSection() { const [currentSlide, setCurrentSlide] = useState(0) const [imageLoading, setImageLoading] = useState(true) const [touchStart, setTouchStart] = useState(null) const [touchEnd, setTouchEnd] = useState(null) const banners: Banner[] = useMemo(() => [ { id: 1, title: "Premium Aged Basmati 1121", subtitle: "Extra Long Grain • 2+ Years Aged", description: "Authentic Basmati rice with exceptional length, distinctive aroma, and fluffy texture from the foothills of Himalayas", image: "/images/rice-hero-slider.jpg", cta: "Shop Premium Rice", ctaLink: "/products?category=rice", bgColor: "from-amber-600 via-yellow-600 to-orange-700" }, { id: 3, title: "Kashmina Brand Collection", subtitle: "Farm Fresh • Direct from Fields", description: "Premium rice varieties sourced directly from trusted farmers, processed with care for exceptional quality", image: "https://4m5m4tx28rtva30c.public.blob.vercel-storage.com/media/2025-09-07/banner-slider-1", cta: "Shop Kashmina", ctaLink: "/products?brand=kashmina", bgColor: "from-emerald-600 via-green-600 to-yellow-600" }, // { // id: 4, // title: "Wholesale Rice Supplies", // subtitle: "Bulk Orders • Competitive Rates", // description: "Reliable wholesale rice supplier offering bulk quantities of premium Basmati and Sella rice for businesses and retailers", // image: "https://4m5m4tx28rtva30c.public.blob.vercel-storage.com/women-carrying-rice", // cta: "Shop Wholesale", // ctaLink: "/wholesaler", // bgColor: "from-orange-600 via-red-600 to-amber-600" // }, { id: 5, title: "Indian Frmer Plowing", subtitle: "Traditional Farming • Heritage Grain", description: "Experience the rich heritage of rice cultivation with traditional farming methods passed down through generations.", image: "https://4m5m4tx28rtva30c.public.blob.vercel-storage.com/media/2025-09-07/indian-farmer-plowing", cta: "Learn More", } ], []) // Debug: Log current slide image useEffect(() => { console.log('Current slide image:', banners[currentSlide]?.image); }, [currentSlide, banners]); const featuredCategories = [ { title: "Kashmina Sella Premium", subtitle: "Extra long grain", link: "/products?brand=basmati-1121", bgColor: "from-amber-500 to-yellow-600" }, { title: "Kashmina Gold Premium", subtitle: "Steam processed", link: "/products?category=sella", bgColor: "from-yellow-500 to-amber-600" }, { title: "Kashmina Steam Premium", subtitle: "Traditional quality", link: "/products?brand=kashmina", bgColor: "from-emerald-500 to-green-600" }, { title: "Wholesale", subtitle: "Wholesale rates", link: "/wholesaler", bgColor: "from-orange-500 to-red-600" } ] useEffect(() => { const timer = setInterval(() => { setCurrentSlide((prev) => (prev + 1) % banners.length) }, 5000) // Auto-slide every 5 seconds return () => clearInterval(timer) }, [banners.length]) // Reset loading state when slide changes useEffect(() => { setImageLoading(true) }, [currentSlide]) const nextSlide = () => { setCurrentSlide((prev) => (prev + 1) % banners.length) } const prevSlide = () => { setCurrentSlide((prev) => (prev - 1 + banners.length) % banners.length) } const goToSlide = (index: number) => { setCurrentSlide(index) } // Touch handlers for mobile swipe const minSwipeDistance = 50 const onTouchStart = (e: React.TouchEvent) => { setTouchEnd(null) // otherwise the swipe is fired even with usual touch events setTouchStart(e.targetTouches[0].clientX) } const onTouchMove = (e: React.TouchEvent) => { setTouchEnd(e.targetTouches[0].clientX) } const onTouchEnd = () => { if (!touchStart || !touchEnd) return const distance = touchStart - touchEnd const isLeftSwipe = distance > minSwipeDistance const isRightSwipe = distance < -minSwipeDistance if (isLeftSwipe) { nextSlide() } else if (isRightSwipe) { prevSlide() } } return (
{/* Amazon-style Hero Layout */}
{/* Main Banner Slider - Left Side (3/4 width) - Better mobile aspect ratio */}
{/* Skeleton Loader for CLS prevention */}
{/* Background Color Fallback */}
{banners[currentSlide].title} setImageLoading(true)} onError={(e) => { console.error('Image failed to load:', banners[currentSlide].image); setImageLoading(false); // Keep the gradient background visible on error const target = e.target as HTMLImageElement; target.style.display = 'none'; }} onLoad={() => { console.log('Image loaded successfully:', banners[currentSlide].image); setImageLoading(false); }} /> {/* Loading overlay */} {imageLoading && (
)} {/* Content positioned in center-left with enhanced visibility */}
{/* Semi-transparent background for text */} {/*

{banners[currentSlide].subtitle}

{banners[currentSlide].title}

{banners[currentSlide].description}

*/}
{/* Subtle Navigation Arrows - Better mobile visibility */} {/* Slide Indicators - Fixed positioning with background */}
{banners.map((_, index) => (
{/* Modern Category Cards - Right Side (1/4 width) - Ultra compact mobile */}
{featuredCategories.slice(0, 4).map((category, index) => (
{/* Gradient Background Accent */}
{/* Content - Ultra Compact Mobile Layout */}
{/* Icon Container - Very small on mobile */}
{/* Typography - Ultra compact */}

{category.title}

{category.subtitle}

{/* Arrow Icon - Hidden on mobile */}
))}
{/* Secondary Strip - Repositioned and Mobile Optimized */} {/*

🌾 Premium Rice • Direct from Farms • Free Shipping ₹500+

Aged Basmati & Golden Sella rice delivered fresh to your kitchen

*/}
) }