import React, { useEffect, useState } from 'react';
import { AuthProvider, AuthGuard, useAuth } from './AdminAuth';
import AdminLayout from './AdminLayout';
import { LineChart, Line, XAxis, YAxis, Tooltip, ResponsiveContainer, BarChart, Bar } from 'recharts';
interface Stats {
total_products: number;
active_feeds: number;
clicks_today: number;
revenue_month: number;
}
function StatCard({ label, value, icon }: { label: string; value: string | number; icon: string }) {
return (
);
}
function DashboardContent() {
const { token } = useAuth();
const [stats, setStats] = useState({ total_products: 0, active_feeds: 0, clicks_today: 0, revenue_month: 0 });
const [timeseries, setTimeseries] = useState([]);
useEffect(() => {
const headers = { Authorization: `Bearer ${token}` };
fetch('/api/admin/stats', { headers }).then(r => r.json()).then(setStats).catch(() => {});
fetch('/api/admin/analytics?type=timeseries&days=30', { headers })
.then(r => r.json()).then(d => setTimeseries(d.data || [])).catch(() => {});
}, [token]);
// Generate mock data if no real data
const chartData = timeseries.length > 0 ? timeseries :
Array.from({ length: 30 }, (_, i) => ({
date: new Date(Date.now() - (29 - i) * 86400000).toISOString().slice(0, 10),
clicks: Math.floor(Math.random() * 200 + 50),
revenue: Math.floor(Math.random() * 100 + 10),
conversions: Math.floor(Math.random() * 10),
}));
return (
Clicks (30 days)
v.slice(5)} />
Revenue (30 days)
v.slice(5)} />
);
}
export default function Dashboard() {
return (
);
}