import { Download, FileJson, FileText, FileSpreadsheet, ChevronDown } from 'lucide-react'; import { useState, useRef, useEffect } from 'react'; interface ExportButtonProps { onExport: (format: 'html' | 'json' | 'csv') => Promise; } export function ExportButton({ onExport }: ExportButtonProps) { const [open, setOpen] = useState(false); const [exporting, setExporting] = useState(null); const ref = useRef(null); useEffect(() => { const handler = (e: MouseEvent) => { if (ref.current && !ref.current.contains(e.target as Node)) setOpen(false); }; document.addEventListener('mousedown', handler); return () => document.removeEventListener('mousedown', handler); }, []); const handleExport = async (format: 'html' | 'json' | 'csv') => { setOpen(false); setExporting(format); try { await onExport(format); } finally { setExporting(null); } }; const options = [ { key: 'html' as const, label: 'HTML Report', desc: 'Self-contained, shareable', icon: }, { key: 'json' as const, label: 'JSON Export', desc: 'Full structured data', icon: }, { key: 'csv' as const, label: 'CSV Summary', desc: 'Spreadsheet-friendly', icon: }, ]; return (
{open && (
{options.map(opt => ( ))}
)}
); }