import { useState } from 'react' import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query' import { Receipt, Download, Trash2, Plus, X } from 'lucide-react' import { toast } from 'sonner' import { getInvoices, createInvoice, updateInvoiceStatus, deleteInvoice, downloadInvoicePdf, type Invoice, type InvoiceCreate, } from '../api/billing' // ── Helpers ─────────────────────────────────────────────────────────────── const formatCurrency = (amount: number | null, currency = 'EUR') => { if (amount == null) return '—' return new Intl.NumberFormat('de-DE', { style: 'currency', currency }).format(amount) } const formatDate = (iso: string | null) => iso ? new Date(iso).toLocaleDateString('de-DE') : '—' const STATUS_COLORS: Record = { draft: 'bg-gray-100 text-gray-700', sent: 'bg-blue-100 text-blue-700', paid: 'bg-green-100 text-green-700', cancelled: 'bg-red-100 text-red-700', } // ── New Invoice Modal ───────────────────────────────────────────────────── function NewInvoiceModal({ onClose, onCreate }: { onClose: () => void; onCreate: (data: InvoiceCreate) => void }) { const [notes, setNotes] = useState('') const [issuedAt, setIssuedAt] = useState(new Date().toISOString().split('T')[0]) const handleSubmit = (e: React.FormEvent) => { e.preventDefault() onCreate({ order_line_ids: [], notes: notes || undefined, issued_at: issuedAt || undefined }) } return (

New Invoice

setIssuedAt(e.target.value)} className="w-full px-3 py-2 text-sm border border-gray-200 rounded-lg focus:outline-none focus:ring-1 focus:ring-blue-500" />