import React from "react"; import { Testimonial, TestimonialsProps } from "../../types"; import { cn } from "../../lib/utils"; import { TestimonialCard } from "./TestimonialCard"; import { motion, AnimatePresence } from "framer-motion"; import { ChevronLeft, ChevronRight, Pause, Play } from "lucide-react"; import { useState, useEffect } from "react"; import { Button } from "../ui/button"; interface CarouselLayoutProps extends Omit { testimonials: Omit[]; } export function CarouselLayout({ testimonials, theme = "light", className, }: CarouselLayoutProps) { const [currentIndex, setCurrentIndex] = useState(0); const [isPlaying, setIsPlaying] = useState(false); const [visibleCount, setVisibleCount] = useState(3); // Adjust visible count based on screen size useEffect(() => { const updateVisibleCount = () => { const width = window.innerWidth; if (width >= 1280) setVisibleCount(3); else if (width >= 768) setVisibleCount(2); else setVisibleCount(1); }; updateVisibleCount(); window.addEventListener("resize", updateVisibleCount); return () => window.removeEventListener("resize", updateVisibleCount); }, []); // Auto-play functionality useEffect(() => { if (!isPlaying) return; const interval = setInterval(() => { setCurrentIndex((prev) => prev >= testimonials.length - visibleCount ? 0 : prev + 1 ); }, 2500); return () => clearInterval(interval); }, [isPlaying, testimonials.length, visibleCount]); const goToPrevious = () => { setCurrentIndex((prev) => prev <= 0 ? testimonials.length - visibleCount : prev - 1 ); }; const goToNext = () => { setCurrentIndex((prev) => prev >= testimonials.length - visibleCount ? 0 : prev + 1 ); }; const visibleTestimonials = testimonials.slice( currentIndex, currentIndex + visibleCount ); return (
{/* Controls */}
{/* Carousel */}
{visibleTestimonials.map((testimonial, index) => ( ))}
{/* Indicators */}
{Array.from({ length: Math.ceil(testimonials.length / visibleCount), }).map((_, index) => (
); }