import React, { useState, useEffect } from 'react'; import { AuthProvider, AuthGuard, useAuth } from './AdminAuth'; import AdminLayout from './AdminLayout'; function StatCard({ label, value, icon }: { label: string; value: string | number; icon: string }) { return (
{label} {icon}
{value}
); } function EmailStatsContent() { const { token } = useAuth(); const [overview, setOverview] = useState(null); const [recent, setRecent] = useState([]); const [mostWatched, setMostWatched] = useState([]); const [tab, setTab] = useState<'overview' | 'recent' | 'watchlist'>('overview'); const [loading, setLoading] = useState(true); const headers = { Authorization: `Bearer ${token}` }; useEffect(() => { Promise.all([ fetch('/api/admin/emails?view=overview', { headers }).then(r => r.json()), fetch('/api/admin/emails?view=recent', { headers }).then(r => r.json()), fetch('/api/admin/emails?view=most-watched', { headers }).then(r => r.json()), ]).then(([ov, rec, mw]) => { setOverview(ov); setRecent(rec.data || []); setMostWatched(mw.data || []); }).finally(() => setLoading(false)); }, []); if (loading) return (
); const emails = overview?.emails || {}; const wl = overview?.watchlist || {}; return ( {/* Sub-nav */}
{(['overview', 'recent', 'watchlist'] as const).map(t => ( ))} ✏️ Email Editor
{tab === 'overview' && ( <>

Email Stats

Watchlist Stats

)} {tab === 'recent' && (
{recent.length === 0 ? (
Geen emails verstuurd
) : ( {recent.map((r: any, i: number) => ( ))}
DatumTypeEmailProductResend ID
{new Date(r.created_at).toLocaleString('nl-NL')} {r.email_type} {r.email || '-'} {r.product_name || '-'} {r.resend_id || '-'}
)}
)} {tab === 'watchlist' && (

Meest Gevolgde Producten

{mostWatched.length === 0 ? (
Geen watchlist data
) : (
{mostWatched.map((p: any, i: number) => (
{i + 1} {p.image_url && }
{p.name}
{p.brand}
{p.watchers} 👀
))}
)}
)}
); } export default function EmailStats() { return ; }