"use client"; import { useState, useRef, useEffect, useCallback } from "react"; import Image from "next/image"; import { Instagram, ChevronLeft, ChevronRight } from "lucide-react"; import { siteContent } from "@/data/content"; import { SectionHeading } from "@/components/ui/SectionHeading"; import { Reveal } from "@/components/ui/Reveal"; import { TeamMemberModal } from "@/components/ui/TeamMemberModal"; import type { TeamMember } from "@/types"; export function Team() { const { team } = siteContent; const [selectedMember, setSelectedMember] = useState(null); const scrollRef = useRef(null); const scrollTimer = useRef>(null); const isDragging = useRef(false); const dragStartX = useRef(0); const dragScrollLeft = useRef(0); const dragMoved = useRef(false); // Render 3 copies: [clone] [original] [clone] const tripled = [...team.members, ...team.members, ...team.members]; // On mount, jump to the middle set (no animation) useEffect(() => { const el = scrollRef.current; if (!el) return; requestAnimationFrame(() => { const cardWidth = el.scrollWidth / 3; el.scrollLeft = cardWidth; }); }, []); // When scroll settles, check if we need to loop const handleScroll = useCallback(() => { if (scrollTimer.current) clearTimeout(scrollTimer.current); scrollTimer.current = setTimeout(() => { const el = scrollRef.current; if (!el) return; const oneSetWidth = el.scrollWidth / 3; if (el.scrollLeft < oneSetWidth * 0.3) { el.style.scrollBehavior = "auto"; el.scrollLeft += oneSetWidth; el.style.scrollBehavior = ""; } if (el.scrollLeft > oneSetWidth * 1.7) { el.style.scrollBehavior = "auto"; el.scrollLeft -= oneSetWidth; el.style.scrollBehavior = ""; } }, 100); }, []); // Mouse drag handlers function handleMouseDown(e: React.MouseEvent) { const el = scrollRef.current; if (!el) return; isDragging.current = true; dragMoved.current = false; dragStartX.current = e.pageX; dragScrollLeft.current = el.scrollLeft; el.style.scrollBehavior = "auto"; el.style.scrollSnapType = "none"; el.style.cursor = "grabbing"; } function handleMouseMove(e: React.MouseEvent) { if (!isDragging.current || !scrollRef.current) return; e.preventDefault(); const dx = e.pageX - dragStartX.current; if (Math.abs(dx) > 3) dragMoved.current = true; scrollRef.current.scrollLeft = dragScrollLeft.current - dx; } function handleMouseUp() { if (!isDragging.current || !scrollRef.current) return; isDragging.current = false; scrollRef.current.style.scrollBehavior = ""; scrollRef.current.style.scrollSnapType = ""; scrollRef.current.style.cursor = ""; } function handleCardClick(member: TeamMember) { // Don't open modal if user was dragging if (dragMoved.current) return; setSelectedMember(member); } function scroll(direction: "left" | "right") { if (!scrollRef.current) return; const amount = scrollRef.current.offsetWidth * 0.7; scrollRef.current.scrollBy({ left: direction === "left" ? -amount : amount, behavior: "smooth", }); } return (
{team.title}
{/* Carousel wrapper */}
{/* Scroll container */}
{tripled.map((member, i) => (
handleCardClick(member)} > {/* Photo */}
{member.name}
{/* Gradient overlay */}
{/* Rose glow on hover */}
{/* Content */}

{member.name}

{member.instagram && ( e.stopPropagation()} > {member.instagram.split("/").filter(Boolean).pop()} )}
))}
{/* Side navigation arrows */}
setSelectedMember(null)} />
); }