'use client'; import { useState } from 'react'; export function ExportButton({ table, label }: { table: string; label?: string }) { const [loading, setLoading] = useState(false); const handleExport = async () => { setLoading(true); try { const res = await fetch('/api/phase2', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ action: 'export', table }), }); if (!res.ok) throw new Error('Export failed'); const blob = await res.blob(); const url = URL.createObjectURL(blob); const a = document.createElement('a'); a.href = url; a.download = `${table}-export.csv`; a.click(); URL.revokeObjectURL(url); } finally { setLoading(false); } }; return ( ); }