import { Pencil, Trash2 } from 'lucide-react' import { toast } from 'sonner' import { Button } from '@/components/ui/button' import { useDeleteEntry, useRestoreEntry } from '@/lib/entries' import { formatDate, formatMoney, formatWeekday } from '@/lib/format' import { group } from '@/lib/groups' import { groupByDay } from '@/lib/ledger' import { t } from '@/lib/strings' import { cn } from '@/lib/utils' import type { CatalogItem } from '@/types/CatalogItem' import type { Entry } from '@/types/Entry' const s = t.ledger /** * Haftanın girişleri, gün gün. Sil → bildirimde "Geri al" (sunucuda soft delete + restore). * Kategori ve ödeme türü adları pasifler dahil listeden bulunur (eski kayıtlar da adıyla görünür). */ export function EntryList({ periodId, entries, categories, methods, editingId, readOnly = false, onEdit, onDeleted, }: { periodId: string entries: Entry[] categories: CatalogItem[] methods: CatalogItem[] editingId?: string /** Kapalı dönem: düzenle/sil yok */ readOnly?: boolean onEdit: (e: Entry) => void onDeleted: (id: string) => void }) { const del = useDeleteEntry(periodId) const restore = useRestoreEntry(periodId) const catName = (id: string) => categories.find((c) => c.id === id) const pmName = (id: string | null) => (id ? methods.find((m) => m.id === id)?.name : undefined) function remove(e: Entry, name: string) { del.mutate(e.id, { onSuccess: () => { onDeleted(e.id) toast(s.deleted, { description: `${formatMoney(e.amount)} · ${name}`, duration: 8000, action: { label: s.undo, onClick: () => restore.mutate(e.id, { onSuccess: () => toast.success(s.restored), onError: (err) => toast.error(err.message), }), }, }) }, onError: (err) => toast.error(err.message), }) } if (entries.length === 0) { return
{s.empty}
} return ({name} {editing && ( · {s.editing} )}
{details[0]} {details.slice(1).map((d) => ` · ${d}`)}