import React, { useState, useRef, useEffect, useCallback } from 'react'; import { ChevronLeft, ChevronRight } from 'lucide-react'; import MessageBubble from './MessageBubble'; const CAROUSEL_BREAKPOINT = 700; const AdvisorCarousel = ({ messages = [], onReply, onExpand, onClick, onSearchReferences, userAvatarId, userAvatarOptions }) => { const [activeIndex, setActiveIndex] = useState(0); const [isCarouselMode, setIsCarouselMode] = useState(false); const containerRef = useRef(null); useEffect(() => { const el = containerRef.current; if (!el) return; const observer = new ResizeObserver(entries => { const width = entries[0].contentRect.width; setIsCarouselMode(width < CAROUSEL_BREAKPOINT); }); observer.observe(el); return () => observer.disconnect(); }, []); useEffect(() => { setActiveIndex(0); }, [messages.length]); const goPrev = useCallback(() => { setActiveIndex(i => Math.max(0, i - 1)); }, []); const goNext = useCallback(() => { setActiveIndex(i => Math.min(messages.length - 1, i + 1)); }, [messages.length]); if (messages.length === 1) { return (