"use client"; import { useState, useEffect } from "react"; import styles from "@/app/channels/[slug]/channel-page.module.css"; import SafeImage from "./SafeImage"; import { Star, Quote } from "lucide-react"; interface Testimonial { quote: string; author: string; role: string; rating: number; image: string; } export default function ChannelTestimonialSlider({ testimonials, staticImage }: { testimonials: Testimonial[], staticImage?: string }) { const [currentIndex, setCurrentIndex] = useState(0); const [isAnimating, setIsAnimating] = useState(false); useEffect(() => { const interval = setInterval(() => { handleNext(); }, 5000); // 5 seconds per slide return () => clearInterval(interval); }, [testimonials.length]); const handleNext = () => { setIsAnimating(true); setTimeout(() => { setCurrentIndex((prev) => (prev + 1) % testimonials.length); setIsAnimating(false); }, 300); }; const current = testimonials[currentIndex]; // Determine what image to show on the left // If staticImage is provided, use it always. // If not, use the current testimonial's image. const leftImageSrc = staticImage || current.image; // Only animate the left image if it is changing (i.e., no staticImage) const leftImageClass = staticImage ? styles.sliderLeftImage : `${styles.sliderLeftImage} ${isAnimating ? styles.fadeOut : styles.fadeIn}`; return (
"{current.quote}"