"use client"; import Link from "next/link"; import { useState, useEffect, useMemo } from "react"; import { useHomeBanners } from "@/lib/hooks/useHome"; const HomeBanner = () => { const [currentTextIndex, setCurrentTextIndex] = useState(0); const [isTransitioning, setIsTransitioning] = useState(false); const { data: banners, loading, error } = useHomeBanners(); // Fix viewport height for mobile browsers (especially iOS Safari) useEffect(() => { const setVH = () => { const vh = window.innerHeight * 0.01; document.documentElement.style.setProperty('--vh', `${vh}px`); }; setVH(); window.addEventListener('resize', setVH); // Use 'resize' event instead of deprecated 'orientationchange' // The resize event fires on orientation change as well const handleOrientationChange = () => { // Small delay to ensure viewport has updated setTimeout(setVH, 100); }; window.addEventListener('resize', handleOrientationChange); return () => { window.removeEventListener('resize', setVH); window.removeEventListener('resize', handleOrientationChange); }; }, []); // Transform API data to match component format const carouselTexts = useMemo(() => { if (!banners || banners.length === 0) return []; return banners.map(banner => ({ icon: banner.icon, badge: banner.badge, heading: banner.heading, highlight: banner.highlight, subheading: banner.subheading, description: banner.description, button_text: banner.button_text, button_url: banner.button_url, })); }, [banners]); // Carousel rotation effect useEffect(() => { if (carouselTexts.length <= 1) return; const interval = setInterval(() => { setIsTransitioning(true); setTimeout(() => { setCurrentTextIndex((prevIndex) => prevIndex === carouselTexts.length - 1 ? 0 : prevIndex + 1 ); setIsTransitioning(false); }, 1000); // Slightly longer for smoother transition }, 6000); // Increased interval for slower changes return () => clearInterval(interval); }, [carouselTexts.length]); const currentText = carouselTexts[currentTextIndex]; // Show loading state if (loading) { return ( Loading... Loading banner content... ); } // Show error state if (error) { return ( Error Loading Content {error} Please try refreshing the page or contact support if the problem persists. ); } // Show no data message when there's no banner content if (!currentText || carouselTexts.length === 0) { return ( No data available ); } return ( <> {/* Industrial Enterprise Background Elements */} {/* Flying Code Elements */} const enterprise = {'{'} security: 'enterprise-grade', scalability: 'unlimited' {'}'}; if (security === 'max') {'{'} deploy.enterprise(); {'}'} class EnterpriseSoftware {'{'} constructor() {'{'} this.secure = true; {'}'} {'}'} API.authenticate({'{'} level: 'enterprise', encryption: 'AES-256' {'}'}); {/* Industrial Grid */} {/* Security Elements */} {/* Circuit Patterns */} {/* Data Streams */} {/* Request/Response Data */} POST /api/enterprise 200 OK GET /api/analytics 201 Created {/* Space Data Generation */} {/* Database Connections */} {/* Real-time Metrics */} API Calls/sec 2,847 Data Processed 15.2TB Active Users 45,892 {currentText.badge} {currentText.heading} {currentText.highlight} {currentText.subheading} {currentText.description} {/* Carousel Indicators */} {carouselTexts.map((_, index) => ( { if (index !== currentTextIndex) { setIsTransitioning(true); setTimeout(() => { setCurrentTextIndex(index); setIsTransitioning(false); }, 1000); } }} /> ))} {currentText.button_text || "Learn More"} Contact Sales 30+ Enterprise Clients 99.9% Uptime SLA 24/7 Enterprise Support window.scrollTo({ top: window.innerHeight, behavior: 'smooth' })}> Scroll to explore > ); }; export default HomeBanner;
Loading banner content...
{error}
Please try refreshing the page or contact support if the problem persists.
{currentText.description}