'use client'; import { useState } from 'react'; import { Button } from '@/components/ui/button'; import { Download } from 'lucide-react'; interface DataExportButtonProps { endpoint: string; params?: Record; } export default function DataExportButton({ endpoint, params }: DataExportButtonProps) { const [loading, setLoading] = useState(false); const handleExport = async (format: 'csv' | 'json') => { setLoading(true); try { const query = new URLSearchParams({ format, ...params }); const res = await fetch(`${endpoint}?${query.toString()}`); 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 = `export.${format}`; a.click(); URL.revokeObjectURL(url); } catch { // Error handled silently — toast can be added later } finally { setLoading(false); } }; return (
); }