import React, { useState, useEffect } from 'react'; import { AuthProvider, AuthGuard, useAuth } from './AdminAuth'; import AdminLayout from './AdminLayout'; function StatCard({ label, value, icon, active, onClick }: { label: string; value: string | number; icon: string; active?: boolean; onClick?: () => void }) { return ( ); } function SubscribersContent() { const { token } = useAuth(); const [subscribers, setSubscribers] = useState([]); const [totals, setTotals] = useState({}); const [filter, setFilter] = useState('all'); const [loading, setLoading] = useState(true); const [selectedUser, setSelectedUser] = useState(null); const [userDetail, setUserDetail] = useState(null); const [detailLoading, setDetailLoading] = useState(false); const headers = { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json' }; const load = (f: string) => { setLoading(true); setFilter(f); fetch(`/api/admin/subscribers?filter=${f}`, { headers }) .then(r => r.json()) .then(res => { setSubscribers(res.data || []); setTotals(res.totals || {}); }) .finally(() => setLoading(false)); }; useEffect(() => { load('all'); }, []); const loadDetail = (user: any) => { setSelectedUser(user); setDetailLoading(true); fetch('/api/admin/subscribers', { method: 'POST', headers, body: JSON.stringify({ userId: user.id }), }) .then(r => r.json()) .then(res => setUserDetail(res)) .finally(() => setDetailLoading(false)); }; return ( {/* Totals */}
load('all')} /> load('verified')} /> load('unverified')} /> load('unsubscribed')} />
{/* Subscribers list */}
{loading ? (
) : subscribers.length === 0 ? (
Geen subscribers gevonden
) : ( {subscribers.map((s: any) => ( loadDetail(s)} className={`border-t border-[#222] cursor-pointer transition-colors ${selectedUser?.id === s.id ? 'bg-[#00FF6A]/5' : 'hover:bg-[#1A1A1A]'}`}> ))}
Email Status Watchlist Alerts Aangemeld
{s.email} {s.unsubscribed ? ( Uitgeschreven ) : s.email_verified ? ( Geverifieerd ) : ( Onbevestigd )} {s.watchlist_count} {s.alert_count} {new Date(s.created_at).toLocaleDateString('nl-NL')}
)}
{/* Detail panel */} {selectedUser && (

{selectedUser.email}

Lid sinds {new Date(selectedUser.created_at).toLocaleDateString('nl-NL')}

{detailLoading ? (
) : userDetail ? (
{/* Email History */} {userDetail.emailHistory?.length > 0 && (

Email Geschiedenis

{userDetail.emailHistory.map((e: any, i: number) => (
{e.email_type} {e.count}× (laatst: {new Date(e.last_sent).toLocaleDateString('nl-NL')})
))}
)} {/* Price Alerts */} {userDetail.alerts?.length > 0 && (

Prijsalerts ({userDetail.alerts.length})

{userDetail.alerts.map((a: any, i: number) => (
{a.name}
{a.brand}
Target: €{parseFloat(a.target_price).toFixed(2)}
{a.current_price && (
Nu: €{parseFloat(a.current_price).toFixed(2)}
)}
))}
)} {/* Watchlist */} {userDetail.watchlist?.length > 0 && (

Watchlist ({userDetail.watchlist.length})

{userDetail.watchlist.map((w: any, i: number) => (
{w.image_url && ( )}
{w.name}
{w.brand}
{w.target_price && ( 🔔 €{parseFloat(w.target_price).toFixed(2)} )}
))}
)} {!userDetail.watchlist?.length && !userDetail.alerts?.length && (
Geen watchlist of alerts
)}
) : null}
)}
); } export default function Subscribers() { return ; }