"use client"; import React, { useState, useRef, useEffect } from 'react'; import Slider from 'react-slick'; import Link from 'next/link'; import GsapReveal from '@/components/common/GsapReveal'; import GoogleReviewsBranding from '@/components/common/GoogleReviewsBranding'; const Testimonial = () => { const [reviews, setReviews] = useState([]); const [loading, setLoading] = useState(true); const sliderRef = useRef(null); useEffect(() => { async function loadReviews() { try { const res = await fetch("/api/reviews"); const data = await res.json(); // Filter for reviews with text (showing ALL reviews as requested) const cleaned = (data.reviews || []).filter((r: any) => (r.snippet || r.text || r.review_text || r.description || r.body || r.content) ); setReviews(cleaned); } catch (error) { console.error("Failed to fetch reviews", error); } finally { setLoading(false); } } loadReviews(); }, []); // If reviews are sparse, duplicate them to ensure infinite slider works perfectly const displayedReviews = reviews.length > 0 && reviews.length < 3 ? [...reviews, ...reviews, ...reviews] : reviews; const settings = { dots: false, arrows: false, infinite: displayedReviews.length > 1, speed: 600, slidesToShow: 1, slidesToScroll: 1, autoplay: true, autoplaySpeed: 5000, responsive: [ { breakpoint: 1024, settings: { slidesToShow: 1, } } ] }; function getReviewText(r: any) { return r.text || r.description || r.snippet || r.review_text || r.body || r.content || ""; } function getProfileImage(r: any) { const url = r.profile_photo_url || r.author_profile_photo_url || r.user?.thumbnail || r.user?.profile_photo_url || r.thumbnail || r.profile_picture || r.avatar || r.author_image; if (!url) return null; if (url.startsWith("http")) return url; return `https://lh3.googleusercontent.com/${url}`; } function getInitials(name: string) { if (!name) return "U"; return name.split(' ').map(n => n.charAt(0)).join('').substring(0, 2).toUpperCase(); } return (
{/* Section Header */}
Testimonials

What Our Clients Say

{/* Content Row */}
{/* Left: Single Primary Image */}
Testimonials
{/* Right: Slider */}
{loading ? (
Loading reviews...

Fetching live Google reviews...

) : displayedReviews.length > 0 ? (
{displayedReviews.map((slide, index) => { const profileImg = getProfileImage(slide); const name = slide.user?.name || slide.author_name || "Valued Client"; return (
{/* Stars */}
{[...Array(slide.rating || 5)].map((_, i) => ( ))}

"{getReviewText(slide)}"

{profileImg ? ( {name} ) : ( {getInitials(name)} )}

{name}

{/*

Verified Google Reviewer

*/}
); })}
) : (

Professional services you can trust.

)} {/* Google Action Button */}
Review us on Google
); }; export default Testimonial;