import { useState, useEffect } from 'react'; import { Building2, TrendingUp, AlertTriangle, ChevronDown, Loader2, RefreshCw, Crown } from 'lucide-react'; import { motion } from 'framer-motion'; import apiClient from '../../api/client'; interface CompanyStats { id: string; name: string; taxId: string; totalInvoices: number; totalTax: number; failedCount: number; riskScore: number; aiStats: { totalTokens: number; totalCost: number; }; } const getRiskStatus = (score: number) => { if (score >= 70) return 'High'; if (score >= 30) return 'Medium'; return 'Low'; }; const RiskGauge = ({ score }: { score: number }) => { const status = getRiskStatus(score); const getColor = () => { if (status === 'High') return 'text-red-500'; if (status === 'Medium') return 'text-orange-500'; return 'text-emerald-500'; }; const getLabel = () => { if (status === 'High') return 'مرتفع'; if (status === 'Medium') return 'متوسط'; return 'منخفض'; }; return (
{score}
{getLabel()}
); }; const Cpu = ({ className }: { className?: string }) => ( ); export const MultiEntityDashboard = () => { const [companies, setCompanies] = useState([]); const [isLoading, setIsLoading] = useState(true); const [error, setError] = useState(null); const fetchData = async () => { setIsLoading(true); setError(null); try { const { data } = await apiClient.get('/dashboard/multi-entity'); setCompanies(data); } catch (err: any) { console.error('Failed to fetch multi-entity stats', err); setError('فشل في جلب بيانات الشركات. تأكد من تسجيل الدخول.'); } finally { setIsLoading(false); } }; useEffect(() => { fetchData(); }, []); if (isLoading) { return (

جاري تحميل بيانات الشركات...

); } return (
{/* Header */}

مُصادَق | لوحة تحكم الشركات

نظرة عامة على الموقف الضريبي لجميع عملائك (Elite View)

{/* Error State */} {error && (
{error}
)} {/* Empty State */} {!error && companies.length === 0 && (

لا توجد شركات بعد

أضف شركات عملائك لتبدأ بمتابعة الموقف الضريبي لكل شركة.

)} {/* Grid */} {companies.length > 0 && (
{companies.map((company, index) => { const status = getRiskStatus(company.riskScore); const approvedEstimate = Math.max(0, company.totalInvoices - company.failedCount); const approvedPct = company.totalInvoices > 0 ? Math.round((approvedEstimate / company.totalInvoices) * 100) : 0; const failedPct = company.totalInvoices > 0 ? Math.round((company.failedCount / company.totalInvoices) * 100) : 0; return ( {/* AI Usage Badge */}
{company.aiStats?.totalTokens > 1000 ? `${(company.aiStats.totalTokens / 1000).toFixed(1)}k` : company.aiStats?.totalTokens || 0} tokens
{/* Ambient glow */}

{company.name}

{company.taxId || '—'}

إجمالي الضريبة

{company.totalTax > 0 ? `${(company.totalTax / 1000).toFixed(1)}k` : '0'}

JOD

درجة الخطر الضريبي

{company.totalInvoices} فاتورة

{company.aiStats?.totalCost > 0 && ( ${company.aiStats.totalCost.toFixed(3)} )} {company.failedCount > 0 && ( {company.failedCount} مرفوضة )}
{/* Progress Bar */}
ناجحة ({approvedPct}%) {company.failedCount > 0 && مرفوضة ({failedPct}%)}
); })}
)}
); };