'use client'; import { useEffect, useState } from 'react'; import { getAIAnalysis } from '@/lib/actions/stock-analysis.actions'; import type { StockAIAnalysis } from '@/lib/actions/stock-analysis.helpers'; interface StockAIAnalysisCardProps { symbol: string; companyName?: string | null; } function getStanceClasses(stance: StockAIAnalysis['stance']) { if (stance === 'Bullish') return 'border-emerald-500/30 bg-emerald-500/10 text-emerald-300'; if (stance === 'Bearish') return 'border-rose-500/30 bg-rose-500/10 text-rose-300'; return 'border-amber-500/30 bg-amber-500/10 text-amber-200'; } function renderList(title: string, items: string[]) { return (

{title}

{items.length ? ( ) : (

No additional signals generated.

)}
); } function LoadingSkeleton() { return (
{[0, 1, 2].map((i) => (
))}
); } function ErrorState() { return (

AI Stock Analysis

Professional research note unavailable

The stock dashboard data loaded, but an AI research note could not be generated right now.

); } export default function StockAIAnalysisCard({ symbol, companyName }: StockAIAnalysisCardProps) { const [analysis, setAnalysis] = useState(null); const [isLoading, setIsLoading] = useState(true); useEffect(() => { let cancelled = false; async function fetchAnalysis() { try { const result = await getAIAnalysis(symbol, companyName); if (!cancelled) { setAnalysis(result); } } catch { if (!cancelled) { setAnalysis(null); } } finally { if (!cancelled) { setIsLoading(false); } } } fetchAnalysis(); return () => { cancelled = true; }; }, [symbol, companyName]); if (isLoading) { return ; } if (!analysis) { return ; } return (

AI Stock Analysis

{analysis.companyName ? `${analysis.companyName} (${analysis.symbol})` : analysis.symbol}

{analysis.summary}

{analysis.stance} {analysis.confidence} confidence
{renderList('Key drivers', analysis.keyDrivers)} {renderList('Risks', analysis.risks)} {renderList('What to watch', analysis.watchItems)}

Educational analysis only. Use it as a synthesis of the dashboard inputs, not as personal financial advice.

); }