'use client' import { useState, useRef } from 'react' import { motion, AnimatePresence } from 'motion/react' import { Search, Bot, ChevronLeft, ChevronRight, Loader2, Check } from 'lucide-react' import { useLanguage } from '@/lib/i18n' import { DashboardWidgetTitleRow } from '@/components/dashboard-widget-title-row' export interface AgentSuggestion { id: string topic: string reason: string relatedNoteCount: number suggestedFrequency: string } export interface CreatedAgentNotice { id: string | null topic: string } export interface DashboardAgentCarouselProps { suggestions: AgentSuggestion[] loading?: boolean actingId: string | null formatFrequency: (f: string) => string onAccept: (id: string) => void onDismiss: (id: string) => void createdAgent?: CreatedAgentNotice | null onOpenCreated?: () => void onClearCreated?: () => void prefersReducedMotion?: boolean } export function DashboardAgentCarousel({ suggestions, loading, actingId, formatFrequency, onAccept, onDismiss, createdAgent, onOpenCreated, onClearCreated, prefersReducedMotion, }: DashboardAgentCarouselProps) { const { t } = useLanguage() const [idx, setIdx] = useState(0) const directionRef = useRef(1) const safeIdx = suggestions.length === 0 ? 0 : Math.min(idx, suggestions.length - 1) const goPrev = () => { directionRef.current = -1 setIdx(i => Math.max(0, i - 1)) } const goNext = () => { directionRef.current = 1 setIdx(i => Math.min(suggestions.length - 1, i + 1)) } const showCreated = !!createdAgent const showNav = !showCreated && suggestions.length > 1 const navActions = showNav ? (
{safeIdx + 1}/{suggestions.length}
) : null if (loading) { return
} return (
} title={t('homeDashboard.suggestedResearch')} actions={navActions} wrapTitle /> {showCreated && createdAgent ? ( 0} onOpen={onOpenCreated} onSeeNext={onClearCreated} t={t} /> ) : suggestions.length === 0 ? (

{t('homeDashboard.agentsEmpty')}

) : ( )}
) } function CreatedAgentPanel({ topic, hasMore, onOpen, onSeeNext, t, }: { topic: string hasMore: boolean onOpen?: () => void onSeeNext?: () => void t: (key: string) => string }) { return (

{t('homeDashboard.agentCreatedInCard')}

{topic ? (

{topic}

) : null}
{hasMore && onSeeNext ? ( ) : null}
) } function AgentSlide({ current, direction, actingId, formatFrequency, onAccept, onDismiss, prefersReducedMotion, t, }: { current: AgentSuggestion direction: number actingId: string | null formatFrequency: (f: string) => string onAccept: (id: string) => void onDismiss: (id: string) => void prefersReducedMotion?: boolean t: (key: string) => string }) { const slide = prefersReducedMotion ? { initial: {}, animate: {}, exit: {} } : { initial: { opacity: 0, x: 14 * direction }, animate: { opacity: 1, x: 0 }, exit: { opacity: 0, x: -14 * direction }, } return (

{current.topic}

{current.reason}

{current.relatedNoteCount} {t('homeDashboard.notes')} ยท {formatFrequency(current.suggestedFrequency)}

) }