import React, { useState, useEffect, useCallback } from 'react'; import { motion, AnimatePresence } from 'framer-motion'; import { BarChart, Bar, XAxis, YAxis, Tooltip, ResponsiveContainer, CartesianGrid, LineChart, Line, PieChart, Pie, Cell, AreaChart, Area, RadarChart, PolarGrid, PolarAngleAxis, PolarRadiusAxis, Radar } from 'recharts'; import { TrendingUp, TrendingDown, Users, DollarSign, ShoppingCart, Activity, Zap, Target, Award, Download, RefreshCw, Eye, BarChart3, PieChart as PieChartIcon, LineChart as LineChartIcon } from 'lucide-react'; import styles from '../styles/EnhancedAnalytics.module.css'; const EnhancedAnalytics = () => { const [analyticsData, setAnalyticsData] = useState(null); const [selectedPeriod, setSelectedPeriod] = useState('30d'); const [selectedChart, setSelectedChart] = useState('line'); const [isLoading, setIsLoading] = useState(true); const [realTimeData, setRealTimeData] = useState({}); const [lastUpdate, setLastUpdate] = useState(new Date()); const generateRealTimeData = useCallback(() => { const now = new Date(); const data = { activeUsers: Math.floor(Math.random() * 100) + 50, currentRevenue: Math.floor(Math.random() * 5000) + 2000, pendingOrders: Math.floor(Math.random() * 20) + 5, systemLoad: Math.floor(Math.random() * 30) + 20, timestamp: now }; setRealTimeData(data); setLastUpdate(now); }, []); const generateAnalyticsData = useCallback(() => { const periods = { '7d': 7, '30d': 30, '90d': 90 }; const days = periods[selectedPeriod]; const data = []; for (let i = days - 1; i >= 0; i--) { const date = new Date(); date.setDate(date.getDate() - i); data.push({ date: date.toLocaleDateString('en-US', { month: 'short', day: 'numeric' }), users: Math.floor(Math.random() * 50) + 20, revenue: Math.floor(Math.random() * 5000) + 1000, orders: Math.floor(Math.random() * 30) + 10, conversion: Math.floor(Math.random() * 20) + 5, engagement: Math.floor(Math.random() * 40) + 20 }); } return data; }, [selectedPeriod]); useEffect(() => { setIsLoading(true); setTimeout(() => { setAnalyticsData(generateAnalyticsData()); generateRealTimeData(); setIsLoading(false); }, 1000); }, [selectedPeriod, generateAnalyticsData, generateRealTimeData]); useEffect(() => { const interval = setInterval(() => { generateRealTimeData(); }, 8000); return () => clearInterval(interval); }, [generateRealTimeData]); const chartColors = { primary: '#3b82f6', secondary: '#1e40af', accent: '#3730a3', success: '#10b981', warning: '#f59e0b', danger: '#ef4444', purple: '#8b5cf6', pink: '#ec4899' }; const RealTimeMetric = ({ title, value, icon: Icon, color, trend, change }) => (

{title}

{value} {trend && ( {trend === 'up' ? : } {change}% )}
); const EnhancedChart = ({ data, type, title, color, height = 300 }) => { const renderChart = () => { switch (type) { case 'line': return ( ); case 'area': return ( ); case 'bar': return ( ); default: return null; } }; return (

{title}

{renderChart()}
); }; if (isLoading) { return (
Loading Analytics...
); } return (
{}

Analytics & Reports

Real-time insights and performance metrics

Live Data Last updated: {lastUpdate.toLocaleTimeString()}
Export Report
{} {} {}

Conversion Rate

24.5%
+2.3% from last month

Average Order Value

$156.78
+5.7% from last month

Customer Satisfaction

4.8/5.0
+0.2 from last month
); }; export default EnhancedAnalytics;