// ============================================================ // MOORE AI v13 — ANALYTICS TAB // Requires: shared/utils.js, shared/components.jsx loaded first // ============================================================ const AnalyticsView = ({ analytics, crmData, loadingTabs, fetchAnalytics }) => { const { useEffect } = React; useEffect(() => { if (!analytics) fetchAnalytics(); }, []); const data = analytics?.totals || {}; const stageData = analytics?.stageCounts || {}; const sourceData = analytics?.sourceBreakdown || {}; const maxStageCount = Math.max(...Object.values(stageData), 1); const maxSourceCount = Math.max(...Object.values(sourceData), 1); return (
Performance Intelligence

Analytics

{loadingTabs.analytics ? (
) : ( <>
o.status === 'open').length} icon="target" color="#8b5cf6" /> o.status === 'won').length} icon="trophy" color="#10b981" /> o.status === 'lost').length} icon="x-circle" color="#ef4444" />
Pipeline by Stage
{Object.entries(stageData).length === 0 ? ( (() => { const stages = {}; crmData.opportunities.forEach(o => { stages[o.stageName || 'Prospect'] = (stages[o.stageName || 'Prospect'] || 0) + 1; }); const max = Math.max(...Object.values(stages), 1); return Object.entries(stages).map(([stage, count], i) => (
{stage} {count}
)); })() ) : Object.entries(stageData).map(([stage, count], i) => (
{stage} {count}
))}
Lead Sources
{Object.entries(sourceData).length === 0 ? ( (() => { const sources = {}; crmData.opportunities.forEach(o => { sources[o.source || 'Direct'] = (sources[o.source || 'Direct'] || 0) + 1; }); const max = Math.max(...Object.values(sources), 1); const colors = ['#3b82f6', '#8b5cf6', '#10b981', '#f59e0b', '#ec4899']; return Object.entries(sources).map(([src, count], i) => (
{src} {count}
)); })() ) : Object.entries(sourceData).map(([src, count], i) => { const colors = ['#3b82f6', '#8b5cf6', '#10b981', '#f59e0b', '#ec4899']; return (
{src} {count}
); })}
Conversion Funnel
{[ { label: 'Total Leads', value: data.total || crmData.stats.totalLeads, color: '#3b82f6' }, { label: 'Open', value: data.open || crmData.opportunities.filter(o => o.status === 'open').length, color: '#8b5cf6' }, { label: 'Won', value: data.won || crmData.opportunities.filter(o => o.status === 'won').length, color: '#10b981' }, { label: 'Lost', value: data.lost || crmData.opportunities.filter(o => o.status === 'lost').length, color: '#ef4444' }, ].map((item, i) => (
{item.value}
{item.label}
))}
)}
); };