import { useState } from 'react' import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query' import toast from 'react-hot-toast' import client from '../api/client' // ── Constants ───────────────────────────────────────────────────────────────── const CATEGORIES = [ { id: 'supplier', label: 'Προμηθευτής' }, { id: 'utilities', label: 'Κοινή Χρεία' }, { id: 'rent', label: 'Ενοίκιο' }, { id: 'maintenance',label: 'Συντήρηση' }, { id: 'staff', label: 'Προσωπικό' }, { id: 'equipment', label: 'Εξοπλισμός' }, { id: 'other', label: 'Άλλο' }, ] const STATUS_CONFIG = { due: { label: 'Οφείλεται', bg: '#fee2e2', color: '#dc2626' }, partial: { label: 'Μερική Πληρ.', bg: '#fef9c3', color: '#a16207' }, paid: { label: 'Πληρώθηκε', bg: '#dcfce7', color: '#16a34a' }, } // ── Helpers ─────────────────────────────────────────────────────────────────── function fmt(n) { if (n == null) return '—' return n.toLocaleString('el-GR', { minimumFractionDigits: 2, maximumFractionDigits: 2 }) + ' €' } function fmtDate(iso) { if (!iso) return '—' return new Date(iso).toLocaleDateString('el-GR', { day: '2-digit', month: '2-digit', year: 'numeric' }) } function fmtDateTime(iso) { if (!iso) return '—' return new Date(iso).toLocaleString('el-GR', { day: '2-digit', month: '2-digit', hour: '2-digit', minute: '2-digit' }) } const inputStyle = { width: '100%', padding: '8px 11px', border: '1px solid #e5e7eb', borderRadius: 8, fontSize: 13.5, outline: 'none', fontFamily: 'inherit', background: 'white', } // ── Expense form modal ──────────────────────────────────────────────────────── const EMPTY_FORM = { description: '', category: 'supplier', contact_id: '', total_amount: '', due_date: '', notes: '' } function ExpenseModal({ initial, contacts, onClose, onSave, isPending }) { const [form, setForm] = useState(initial ?? EMPTY_FORM) const f = (k, v) => setForm(p => ({ ...p, [k]: v })) const isNew = !initial?.id const canSave = form.description.trim() && parseFloat(form.total_amount) > 0 return (

{isNew ? 'Νέο Έξοδο' : 'Επεξεργασία Εξόδου'}

f('description', e.target.value)} autoFocus placeholder="π.χ. Τιμολόγιο Νοεμβρίου — Γαλακτοκομικά" />
f('total_amount', e.target.value)} placeholder="0.00" />
f('due_date', e.target.value)} />