/** * @component HeroBanner * @purpose Main Homepage Hero Banner slider fetching 100% dynamic CMS content from DB 2 via Storefront API. * @dependencies storefrontService, lucide-react */ 'use client'; import { useState, useEffect } from 'react'; import Image from 'next/image'; import Link from 'next/link'; import { ChevronLeft, ChevronRight, ShoppingCart } from 'lucide-react'; import { storefrontService, BannerItem } from '@/services/api/storefrontService'; export function HeroBanner() { const [banners, setBanners] = useState([]); const [currentSlide, setCurrentSlide] = useState(0); useEffect(() => { // Fetch live layout content from backend fetch('http://127.0.0.1:8000/api/v1/storefront/layout/home?region=hero') .then((res) => (res.ok ? res.json() : [])) .then((data) => { if (data && data.length > 0) { const items: BannerItem[] = data.map((d: any) => ({ id: d.content_id, title: d.title, subtitle: d.subtitle || '', discount_tag: d.metadata?.discount_tag || 'SPECIAL OFFER', image_url: d.image_url || '', cta_text: d.button_text || 'Shop Now', cta_link: d.button_url || '/products', })); setBanners(items); } else { // Fallback to storefrontService storefrontService.getBanners().then(setBanners); } }) .catch(() => { storefrontService.getBanners().then(setBanners); }); }, []); useEffect(() => { if (banners.length <= 1) return; const timer = setInterval(() => { setCurrentSlide((prev) => (prev + 1) % banners.length); }, 6000); return () => clearInterval(timer); }, [banners.length]); if (!banners || banners.length === 0) return null; const current = banners[currentSlide] || banners[0]; return (
{/* Main Hero Slider (Takes 2 Columns) */}
{current.title}
{current.discount_tag}

{current.title}

{current.subtitle}

{current.cta_text}
{/* Navigation Controls */} {banners.length > 1 && ( <> )}
{/* 2 Right Promo Cards (Takes 1 Column) */}
Certified Repair Booking
iFixKart Repair Hub

Same-Day Screen & Battery Repair

Book certified technician pickup in 60s

Book Repair
OEM Spare Parts
100% Genuine Spare Parts

Original Display Assemblies & Batteries

12-Month replacement warranty

Browse Parts
); }