"use client"; import { useState } from "react"; import Image from "next/image"; import { IconPlayerPauseFilled, IconPlayerPlayFilled, IconPoint, IconPointFilled } from '@tabler/icons-react'; import type { Testimonial } from "@/shared/types"; import { colors } from "@/constants/colors"; const ROTATE_MS = 10000; function getInitials(name: string) { return name .split(/\s+/) .map((part) => part[0]?.toUpperCase() ?? "") .slice(0, 2) .join(""); } type TestimonialsProps = { items: Testimonial[]; }; export default function Testimonials({ items }: TestimonialsProps) { const [activeIndex, setActiveIndex] = useState(0); const [isPlaying, setIsPlaying] = useState(true); // Hovering or focusing the card pauses rotation so nobody loses their place mid-read. const [isHovered, setIsHovered] = useState(false); const [isFocused, setIsFocused] = useState(false); const shouldRotate = items.length > 1 && isPlaying && !isHovered && !isFocused; if (items.length === 0) return null; // Clamp in case items shrinks underneath us. const current = Math.min(activeIndex, items.length - 1); return (
setIsHovered(true)} onMouseLeave={() => setIsHovered(false)} // Only keyboard focus pauses. A mouse click also focuses the dot, and that // focus would otherwise keep rotation paused after the pointer leaves. onFocus={(e) => setIsFocused(e.target.matches(":focus-visible"))} onBlur={(e) => { if (!e.currentTarget.contains(e.relatedTarget)) setIsFocused(false); }} >
{/* Every slide sits in the same grid cell, so the card is always as tall as the longest testimonial and nothing below it jumps on rotation. */}
{items.map((item, i) => (
“ {item.quote} ”
{item.avatar ? ( ) : (
{getInitials(item.name)}
)}
{item.name}
{item.title}
))}
{items.length > 1 && ( )}
); }