'use client';
import { ReactNode, useEffect, useState } from 'react';
export interface CarouselIndicatorsProps {
totalSlides: number;
activeIndex: number;
onSelect: (index: number) => void;
className?: string;
}
export function CarouselIndicators({ totalSlides, activeIndex, onSelect, className = '' }: CarouselIndicatorsProps) {
return (
{Array.from({ length: totalSlides }).map((_, index) => (
);
}
export interface CarouselProps {
slides: ReactNode[];
autoPlay?: boolean;
interval?: number;
showIndicators?: boolean;
indicatorsClassName?: string;
className?: string;
}
export function Carousel({
slides,
autoPlay = true,
interval = 5000,
showIndicators = true,
indicatorsClassName = '',
className = ''
}: CarouselProps) {
const [activeSlide, setActiveSlide] = useState(0);
// Auto-advance carousel if autoPlay is enabled
useEffect(() => {
if (!autoPlay) return;
const timer = setInterval(() => {
setActiveSlide((prev) => (prev === slides.length - 1 ? 0 : prev + 1));
}, interval);
return () => clearInterval(timer);
}, [autoPlay, interval, slides.length]);
return (
{/* All slides need to be absolutely positioned */}
{slides.map((slide, index) => (
{slide}
))}
{showIndicators && slides.length > 1 && (
)}
);
}