import React, { useState, useEffect } from 'react'; import { Sparkles, TrendingUp, AlertTriangle, Lightbulb, RefreshCw } from 'lucide-react'; import { FinancialSummary, Company, Expense } from '../types'; interface AIInsightsWidgetProps { financialSummary: FinancialSummary; topClients: Company[]; expenses: Expense[]; } export const AIInsightsWidget: React.FC = ({ financialSummary, topClients, expenses }) => { const [isLoading, setIsLoading] = useState(false); const [insights, setInsights] = useState<{type: 'success' | 'warning' | 'info' | 'danger', title: string, message: string}[]>([]); const generateInsights = () => { setIsLoading(true); // Simulating AI processing time setTimeout(() => { const newInsights: typeof insights = []; // 1. Profitability Analysis const margin = financialSummary.totalRevenue > 0 ? (financialSummary.profit / financialSummary.totalRevenue) * 100 : 0; if (margin > 20) { newInsights.push({ type: 'success', title: 'Alta Rentabilidade', message: `Sua margem de lucro de ${margin.toFixed(1)}% está acima da média do mercado.` }); } else if (margin < 5 && margin > 0) { newInsights.push({ type: 'warning', title: 'Margem Apertada', message: 'Lucro abaixo de 5%. Recomendamos revisão imediata de custos fixos.' }); } else if (margin <= 0) { newInsights.push({ type: 'danger', title: 'Prejuízo Operacional', message: 'As despesas superaram as receitas. Verifique inadimplência e corte gastos.' }); } else { newInsights.push({ type: 'info', title: 'Estabilidade', message: 'Sua margem está estável. Busque novas fontes de receita para crescer.' }); } // 2. Cash Flow Analysis if (financialSummary.receivablePending > financialSummary.payablePending) { newInsights.push({ type: 'info', title: 'Caixa Saudável', message: `Previsão de entrada líquida de R$ ${(financialSummary.receivablePending - financialSummary.payablePending).toLocaleString('pt-BR')}.` }); } else { newInsights.push({ type: 'danger', title: 'Risco de Liquidez', message: 'Contas a pagar superam os recebíveis previstos. Aumente o esforço de cobrança.' }); } // 3. Strategic / Growth if (topClients.length > 0) { newInsights.push({ type: 'success', title: 'Oportunidade de Upsell', message: `O cliente ${topClients[0].fantasyName || topClients[0].name} tem alto potencial. Ofereça novos serviços.` }); } else { newInsights.push({ type: 'warning', title: 'Base de Clientes', message: 'Cadastre mais clientes para receber insights de vendas personalizados.' }) } setInsights(newInsights); setIsLoading(false); }, 1500); }; useEffect(() => { generateInsights(); }, [financialSummary]); return (

AI Insights

Análise financeira inteligente

{isLoading ? ( // Skeleton Loading Style [1, 2, 3].map(i => (
)) ) : ( insights.map((insight, idx) => (
{insight.type === 'success' && } {insight.type === 'warning' && } {insight.type === 'danger' && } {insight.type === 'info' && }

{insight.title}

{insight.message}

)) )}
); };