"use client"; import { useRef, useEffect, useState } from "react"; import Image from "next/image"; type Client = { name: string; logoUrl: string; }; type ClientLogosSectionProps = { title: string; description?: string; clients: Client[]; speed?: number; // pixels per frame squareSize?: number; }; const ClientLogosSection = ({ title, description, clients = [], speed = 1, squareSize = 120, }: ClientLogosSectionProps) => { if (clients.length === 0) return null; const extendedClients = [...clients, ...clients]; const squareDim = `${squareSize}px`; const padding = Math.round(squareSize / 6); const paddingDim = `${padding}px`; const scrollRef = useRef(null); const [direction, setDirection] = useState<"left" | "right">("left"); const [paused, setPaused] = useState(false); let resumeTimeout: NodeJS.Timeout; const pauseAndScroll = (dir: "left" | "right") => { if (!scrollRef.current) return; setPaused(true); // Scroll manually scrollRef.current.scrollBy({ left: dir === "left" ? -200 : 200, behavior: "smooth", }); // Clear previous timeout and resume after 3 seconds clearTimeout(resumeTimeout); resumeTimeout = setTimeout(() => { setPaused(false); }, 3000); // Set the direction for automatic scroll after pause setDirection(dir === "left" ? "right" : "left"); }; useEffect(() => { const container = scrollRef.current; if (!container) return; let animationFrame: number; const step = () => { if (!paused) { if (direction === "left") { container.scrollLeft += speed; if (container.scrollLeft >= container.scrollWidth / 2) container.scrollLeft = 0; } else { container.scrollLeft -= speed; if (container.scrollLeft <= 0) container.scrollLeft = container.scrollWidth / 2; } } animationFrame = requestAnimationFrame(step); }; animationFrame = requestAnimationFrame(step); return () => cancelAnimationFrame(animationFrame); }, [direction, paused, speed]); return (

{title}

{/* Logos Container */}
{extendedClients.map((client, index) => (
{`${client.name}
))}
{/* Arrow Controls */}
{description && (

{description}

)}
); }; export const defaultClients: Client[] = [ { name: "ABSA", logoUrl: "/images/absa.png" }, { name: "SYBRIN", logoUrl: "/images/sybrin.svg" }, { name: "SASOL", logoUrl: "/images/sasol.png" }, { name: "JACARANDA", logoUrl: "/images/jacaranda.png" }, { name: "SALESFORCE", logoUrl: "/images/salesforce.png" }, { name: "BCX", logoUrl: "/images/bcx.png" }, { name: "TOYOTA", logoUrl: "/images/toyota-logo.png" }, ]; export default ClientLogosSection;