'use client'; import { useState } from 'react'; interface ExportMenuProps { sessionId: string; disabled?: boolean; } export default function ExportMenu({ sessionId, disabled }: ExportMenuProps) { const [open, setOpen] = useState(false); const [exporting, setExporting] = useState(null); const handleExport = async (format: string) => { setExporting(format); try { if (format === 'copy') { const res = await fetch(`/api/export/copy`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ session_id: sessionId }), }); const data = await res.json(); await navigator.clipboard.writeText(data.text); alert('Copied to clipboard!'); } else { const res = await fetch(`/api/export/${format}`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ session_id: sessionId }), }); const blob = await res.blob(); const url = URL.createObjectURL(blob); const a = document.createElement('a'); a.href = url; a.download = `output.${format === 'excel' ? 'xlsx' : format}`; a.click(); URL.revokeObjectURL(url); } } catch (e) { console.error('Export failed:', e); } finally { setExporting(null); setOpen(false); } }; const formats = [ { key: 'copy', label: '📋 Copy to Clipboard', ext: '' }, { key: 'docx', label: '📄 Word Document', ext: '.docx' }, { key: 'excel', label: '📊 Excel Spreadsheet', ext: '.xlsx' }, { key: 'pdf', label: '📕 PDF Document', ext: '.pdf' }, ]; return (
{open && (
{formats.map((f) => ( ))}
)}
); }