import React, { useState, useEffect } from 'react'; import { ChevronLeft, ChevronRight } from 'lucide-react'; import type { Banner } from '../../content/services/bannerService'; interface BannerCarouselProps { banners: Banner[]; children?: React.ReactNode; } const BannerCarousel: React.FC = ({ banners, children }) => { const [currentIndex, setCurrentIndex] = useState(0); const [isAnimating, setIsAnimating] = useState(false); useEffect(() => { if (banners.length <= 1) return; const interval = setInterval(() => { setCurrentIndex((prev) => prev === banners.length - 1 ? 0 : prev + 1 ); }, 5000); return () => clearInterval(interval); }, [banners.length]); const goToPrevious = () => { if (isAnimating) return; setIsAnimating(true); setCurrentIndex((prev) => prev === 0 ? banners.length - 1 : prev - 1 ); setTimeout(() => setIsAnimating(false), 800); }; const goToNext = () => { if (isAnimating) return; setIsAnimating(true); setCurrentIndex((prev) => prev === banners.length - 1 ? 0 : prev + 1 ); setTimeout(() => setIsAnimating(false), 800); }; const goToSlide = (index: number) => { if (isAnimating || index === currentIndex) return; setIsAnimating(true); setCurrentIndex(index); setTimeout(() => setIsAnimating(false), 800); }; // Don't render if no banners - only show banners from API if (banners.length === 0) { return null; } const currentBanner = banners[currentIndex]; return (
{}
{banners.map((banner, index) => (
{banner.link_url ? ( {banner.title} ) : ( {banner.title} )}
))} {}
{}
{} {currentBanner.title && (
{}
{}

{currentBanner.title}

{} {currentBanner.description && (

{currentBanner.description}

)} {}
{}
{}
{[...Array(3)].map((_, i) => (
))}
)} {} {children && (
{children}
)}
{} {banners.length > 1 && ( <> )} {} {banners.length > 1 && (
{banners.map((_, index) => (
)} {}
); }; export default BannerCarousel;