"use client"; import React, { useState, useEffect } from "react"; import Slider from "react-slick"; import Link from "next/link"; import GoogleReviewsBranding from "@/components/common/GoogleReviewsBranding"; const TestimonialsSection = ({ className = "section-space" }: { className?: string }) => { const [reviews, setReviews] = useState([]); const [loading, setLoading] = useState(true); useEffect(() => { async function loadReviews() { try { const res = await fetch("/api/reviews"); const data = await res.json(); 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(); }, []); const displayedReviews = reviews.length > 0 && reviews.length < 4 ? [...reviews, ...reviews, ...reviews] : reviews; const settings = { dots: false, arrows: false, infinite: displayedReviews.length > 2, speed: 600, slidesToShow: 2, slidesToScroll: 1, autoplay: true, autoplaySpeed: 5000, dotsClass: "testimonial-dot-inner", responsive: [ { breakpoint: 1200, settings: { slidesToShow: 2, } }, { breakpoint: 991, 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, index: number) { // Primary source for SerpAPI Google Maps reviews is user.thumbnail let url = r.user?.thumbnail || r.profile_photo_url || r.author_profile_photo_url || r.user?.profile_photo_url || r.thumbnail || r.profile_picture || r.avatar || r.author_image; if (!url) return `/assets/imgs/resources/testimonials-${(index % 2) + 1}.png`; if (typeof url === 'string') { // Enhance quality for Google URLs (replace =sXX or sXX-c with larger size) if (url.includes('googleusercontent.com')) { // Replace =s120, =s64, etc. with =s400 for high resolution url = url.replace(/=s\d+(-c)?/g, '=s400'); } if (url.startsWith("http")) return url; return `https://lh3.googleusercontent.com/${url}`; } return `/assets/imgs/resources/testimonials-${(index % 2) + 1}.png`; } return (
What they're talking about us
{/*
*/}
{/*
*/}
TESTIMONIALS

Our Client Feedback

{/* */}
{loading ? (

Loading reviews from Google...

) : displayedReviews.length > 0 ? ( {displayedReviews.map((slide, index) => { const profileImg = getProfileImage(slide, index); const name = slide.user?.name || slide.author_name || "Valued Client"; const rating = slide.rating || 5; return (
{name}

{name}

Verified Google Review
    {[...Array(rating)].map((_, i) => (
  • ))}

"{getReviewText(slide)}"

); })}
) : (

No reviews found.

)}
{/* Centered Action Button at Bottom */}
Review us on Google
); }; export default TestimonialsSection;