import React, { useState, useEffect } from 'react'; import StatisticsCard from './StatisticsCard'; import TopSellingProduct from './TopSellingProduct'; import SalesByLocation from './SalesByLocation'; import { Box, useTheme, useMediaQuery, Skeleton, Button, Typography, ButtonGroup } from '@mui/material'; import CalendarTodayOutlinedIcon from '@mui/icons-material/CalendarTodayOutlined'; const AnalyticsPage = () => { const [timeFrame, setTimeFrame] = useState('month'); const theme = useTheme(); const isSmallScreen = useMediaQuery(theme.breakpoints.down('sm')); const isMobile = useMediaQuery(theme.breakpoints.down('sm')); const [hasProducts, setHasProducts] = useState(false); const [isLoading, setIsLoading] = useState(true); const [sidebarOpen, setSidebarOpen] = useState(!isMobile); const dailyData = [ { date: '10:00', visitors: 1500, conversions: 300 }, { date: '11:00', visitors: 1800, conversions: 320 }, ]; const weeklyData = [ { label: 'Week 1', visitors: 1500, conversions: 200 }, { label: 'Week 2', visitors: 2300, conversions: 400 }, ]; const monthlyData = [ { label: 'Jan', visitors: 15000, conversions: 3000 }, { label: 'Feb', visitors: 18000, conversions: 4000 }, ]; const yearlyData = [ { label: '2024', visitors: 25000, conversions: 7000 }, { label: '2025', visitors: 38000, conversions: 12000 }, ]; const getData = () => { switch (timeFrame) { case '24h': return dailyData; case '7d': return weeklyData; case '30d': return monthlyData; case '12m': return yearlyData; case 'all': return [...yearlyData, ...monthlyData, ...weeklyData, ...dailyData]; default: return dailyData; } }; const topSellingProducts = [ { product: 'Apple Watch', sales: 150, amount: 45000, price: 299, status: 'Published' }, { product: 'Samsung Galaxy', sales: 90, amount: 36000, price: 400, status: 'Low Stock' }, { product: 'Sony Headphones', sales: 60, amount: 18000, price: 299, status: 'Draft' }, ]; const salesData = [ { country: 'United Kingdom', amount: 17678, change: 12, sales: 340 }, { country: 'Spain', amount: 5500, change: -5, sales: 100 }, { country: 'Germany', amount: 24189, change: -25, sales: 540 }, ]; useEffect(() => { const checkProducts = async () => { setIsLoading(true); const productsExist = await new Promise((resolve) => setTimeout(() => resolve(true), 1500) ); setHasProducts(productsExist); setIsLoading(false); }; checkProducts(); }, []); useEffect(() => { const handleResize = () => { setSidebarOpen(window.innerWidth >= theme.breakpoints.values.md); }; handleResize(); window.addEventListener('resize', handleResize); return () => window.removeEventListener('resize', handleResize); }, [theme.breakpoints.values.md]); return ( {/* Header Buttons */} {[ { label: 'All Time', value: 'all' }, { label: '12 Months', value: '12m' }, { label: '30 Days', value: '30d' }, { label: '7 Days', value: '7d' }, { label: '24 Hour', value: '24h' }, ].map(({ label, value }) => ( ))} {/* Data Sections */} {/* Chart Section */} {isLoading ? ( <> ) : ( )} ); }; export default AnalyticsPage;