"use client"; import { useEffect, useState } from "react"; import Image from "next/image"; import { IconPlayerPauseFilled, IconPlayerPlayFilled, IconPoint, IconPointFilled } from '@tabler/icons-react'; function getInitials(name: string) { return name .split(/\s+/) .map((part) => part[0]?.toUpperCase() ?? "") .slice(0, 2) .join(""); } type Testimonial = { name: string; title: string; avatar?: string; quote: string; }; type TestimonialsProps = { items: Testimonial[]; }; export default function Testimonials({ items }: TestimonialsProps) { const [activeIndex, setActiveIndex] = useState(0); const [isPlaying, setIsPlaying] = useState(true); const active = items[activeIndex]; if (!active) return null; useEffect(() => { if (items.length <= 1 || !isPlaying) return; const id = setInterval(() => { setActiveIndex((i) => (i + 1) % items.length); }, 5000); return () => clearInterval(id); }, [items.length, isPlaying]); // TODO: fix bug - when clicking a pagination button, the auto-rotation timer doesn't reset, causing it to immediately rotate to the next testimonial after 5 seconds instead of 10 return (
{/* header: avatar + name + title */}
{active.avatar ? ( {active.name} ) : (
{getInitials(active.name)}
)}
{active.name}
{active.title}
"{active.quote}"
); }