'use client' import { useState } from 'react' interface ExportButtonProps { tripId: number shareCode: string } export default function ExportButton({ tripId, shareCode }: ExportButtonProps) { const [loading, setLoading] = useState(false) const [showMenu, setShowMenu] = useState(false) const downloadFile = async (url: string, filename: string) => { try { setLoading(true) const response = await fetch(url) if (!response.ok) { throw new Error('Failed to download file') } const blob = await response.blob() const downloadUrl = window.URL.createObjectURL(blob) const link = document.createElement('a') link.href = downloadUrl link.download = filename document.body.appendChild(link) link.click() document.body.removeChild(link) window.URL.revokeObjectURL(downloadUrl) } catch (err) { console.error('Download failed:', err) alert('Failed to download file. Please try again.') } finally { setLoading(false) setShowMenu(false) } } const exportExpenses = () => { // Use relative URL for mobile compatibility const url = `/api/export/${tripId}/expenses/csv` const filename = `expenses_trip_${tripId}_${shareCode}.csv` downloadFile(url, filename) } const exportPDF = () => { // Use relative URL for mobile compatibility const url = `/api/export/${tripId}/expenses/pdf` const filename = `trip_${tripId}_${shareCode}_report.pdf` downloadFile(url, filename) } return (