'use client' import { useTranslations } from 'next-intl' import { Dialog, DialogContent, DialogHeader, DialogTitle, } from '@/components/ui/dialog' import JournalEntryForm, { type FormLine } from '@/components/bookkeeping/JournalEntryForm' import type { JournalEntry, JournalEntryLine } from '@/types' interface Props { entry: JournalEntry open: boolean onOpenChange: (open: boolean) => void /** Fired after the draft is successfully updated. */ onUpdated: () => void } /** * Edit a DRAFT verifikat. Wraps JournalEntryForm in edit mode, pre-filled from * the draft's header + lines; the form PATCHes the entry in place and it stays * a draft (the user posts it separately). Only ever opened for status==='draft' * entries — the engine + DB triggers reject edits on committed entries anyway. */ export default function EditDraftEntryDialog({ entry, open, onOpenChange, onUpdated }: Props) { const t = useTranslations('bookkeeping') const initialLines: FormLine[] = ((entry.lines || []) as JournalEntryLine[]) .slice() .sort((a, b) => a.sort_order - b.sort_order) .map((l) => ({ account_number: l.account_number, debit_amount: Number(l.debit_amount) > 0 ? String(l.debit_amount) : '', credit_amount: Number(l.credit_amount) > 0 ? String(l.credit_amount) : '', line_description: l.line_description || '', })) return ( e.preventDefault()} onInteractOutside={(e) => e.preventDefault()} > {t('edit_draft_dialog_title')} ) }