import { useState } from 'react'; import { Plus, Pencil, Trash2, TrendingUp } from 'lucide-react'; import { fmt, parseAmount } from '../utils.js'; import Modal from './Modal.jsx'; const TYPE_LABELS = { salary: { label: 'Lön', color: 'bg-blue-100 text-blue-700' }, benefit: { label: 'Förmån', color: 'bg-purple-100 text-purple-700' }, optional: { label: 'Valfri', color: 'bg-amber-100 text-amber-700' }, other: { label: 'Övrigt', color: 'bg-slate-100 text-slate-600' }, }; function IncomeForm({ initial, onSave, onClose }) { const [name, setName] = useState(initial?.name ?? ''); const [amount, setAmount] = useState(initial?.amount ?? ''); const [type, setType] = useState(initial?.type ?? 'salary'); const [notes, setNotes] = useState(initial?.notes ?? ''); function submit(e) { e.preventDefault(); if (!name.trim() || isNaN(parseAmount(amount))) return; onSave({ name: name.trim(), amount: parseAmount(amount), type, notes: notes.trim() || null }); onClose(); } return (
); } export default function IncomeSection({ income, monthId, onAdd, onUpdate, onDelete }) { const [modal, setModal] = useState(null); // null | 'add' | {edit: item} const mandatory = income.filter(i => i.type !== 'optional' && i.type !== 'benefit'); const optional = income.filter(i => i.type === 'optional'); const benefits = income.filter(i => i.type === 'benefit'); const totalMandatory = mandatory.reduce((s, i) => s + i.amount, 0); return (Inga inkomster tillagda
)}