'use client'; import Link from 'next/link'; import { usePathname } from 'next/navigation'; import { useState, useEffect } from 'react'; interface Domain { bucket: string; domain: string; } export function Sidebar() { const pathname = usePathname(); const [domains, setDomains] = useState([]); const [expandedDomains, setExpandedDomains] = useState>(new Set()); const [totalEmails, setTotalEmails] = useState(0); useEffect(() => { // Fetch domains from API const auth = localStorage.getItem('auth'); if (!auth) return; fetch('/api/domains', { headers: { Authorization: `Basic ${auth}` } }) .then(res => res.json()) .then(data => { setDomains(data); }) .catch(err => console.error('Failed to fetch domains:', err)); }, []); const toggleDomain = (bucket: string) => { setExpandedDomains(prev => { const next = new Set(prev); if (next.has(bucket)) { next.delete(bucket); } else { next.add(bucket); } return next; }); }; return ( ); }