import { useTranslation } from "react-i18next"; import { Pencil, RefreshCw } from "lucide-react"; import type { Adjustment, Category } from "../../shared/types"; import type { AdjustmentEntryWithCategory } from "../../services/adjustmentService"; import type { AdjustmentFormData, EntryFormData } from "../../hooks/useAdjustments"; import { confirmAction } from "../../services/confirmService"; import AdjustmentForm from "./AdjustmentForm"; interface Props { selectedAdjustment: Adjustment | null; entries: AdjustmentEntryWithCategory[]; categories: Category[]; editingAdjustment: AdjustmentFormData | null; editingEntries: EntryFormData[]; isCreating: boolean; isSaving: boolean; onStartEditing: () => void; onCancelEditing: () => void; onSave: (data: AdjustmentFormData, entries: EntryFormData[]) => void; onDelete: (id: number) => void; } export default function AdjustmentDetailPanel({ selectedAdjustment, entries, categories, editingAdjustment, editingEntries, isCreating, isSaving, onStartEditing, onCancelEditing, onSave, onDelete, }: Props) { const { t } = useTranslation(); const handleDelete = async () => { if (!selectedAdjustment) return; if (!(await confirmAction(t("adjustments.deleteConfirm")))) return; onDelete(selectedAdjustment.id); }; // No selection and not creating if (!selectedAdjustment && !isCreating) { return (

{t("adjustments.selectAdjustment")}

); } // Creating new if (isCreating && editingAdjustment) { return (

{t("adjustments.newAdjustment")}

); } if (!selectedAdjustment) return null; // Editing existing if (editingAdjustment) { return (

{t("adjustments.editAdjustment")}

); } // Read-only view const total = entries.reduce((sum, e) => sum + e.amount, 0); return (

{selectedAdjustment.name}

{selectedAdjustment.is_recurring && ( )}
{t("adjustments.date")}

{selectedAdjustment.date}

{t("adjustments.recurring")}

{selectedAdjustment.is_recurring ? "Yes" : "No"}

{selectedAdjustment.description && (
{t("adjustments.description")}

{selectedAdjustment.description}

)}
{/* Entries table */}

{t("adjustments.entries")}

{entries.length === 0 ? (

{t("adjustments.noEntries")}

) : ( {entries.map((entry) => ( ))}
{t("adjustments.category")} {t("adjustments.description")} {t("adjustments.amount")}
{entry.category_name}
{entry.description || "—"} = 0 ? "text-[var(--positive)]" : "text-[var(--negative)]" }`} > {entry.amount >= 0 ? "+" : ""} {entry.amount.toFixed(2)}
{t("adjustments.total")} = 0 ? "text-[var(--positive)]" : "text-[var(--negative)]" }`} > {total >= 0 ? "+" : ""} {total.toFixed(2)}
)}
); }