"use client"; import React, { useState, useRef, useEffect } from "react"; import { motion } from "framer-motion"; import { Quote, ChevronLeft, ChevronRight } from "lucide-react"; import Image from "next/image"; import { getCookie } from "cookies-next"; interface TestimonialData { name: string; position: string; image: string; quote: string; } interface TestimonialsDict { title: string; description: string; data: TestimonialData[]; } interface TestimonialsProps { dict: { website: { homePage: { testimonials: TestimonialsDict; }; }; }; } export default function Testimonials({ dict }: TestimonialsProps) { const [currentIndex, setCurrentIndex] = useState(0); const scrollRef = useRef(null); const [locale, setLocale] = useState("en"); useEffect(() => { const sl = getCookie("selectedLocale"); const dl = getCookie("defaultLocale"); setLocale(sl || dl || "en"); }, []); const isRTL = locale === "fa"; const tData = dict.website.homePage.testimonials.data || []; const maxIndex = Math.max(0, tData.length - 3); const scrollTo = (index: number) => { const idx = Math.max(0, Math.min(index, maxIndex)); setCurrentIndex(idx); scrollRef.current?.children[idx]?.scrollIntoView({ behavior: "smooth", block: "nearest", inline: "start" }); }; const handlePrev = () => scrollTo(currentIndex - 1); const handleNext = () => scrollTo(currentIndex + 1); return (
{dict.website.homePage.testimonials.title} {dict.website.homePage.testimonials.description}
{tData.map((testimonial, index) => (

"{testimonial.quote}"

{testimonial.name}
{testimonial.name}

{testimonial.position}

Verified
))}
{tData.length > 3 && ( <>
{Array.from({ length: maxIndex + 1 }).map((_, i) => (
)}
); }