'use client' import { useTranslations } from 'next-intl' import { Copy, Loader2, MessageCircle } from 'lucide-react' import { Dialog, DialogContent, DialogHeader, DialogTitle, } from '@/components/ui/dialog' import JournalEntryForm, { type FormLine } from '@/components/bookkeeping/JournalEntryForm' import { useAgentSheet } from '@/components/agent/AgentSheetProvider' export interface CopyPrefill { sourceId: string sourceVoucherLabel: string lines: FormLine[] description: string notes: string } interface Props { open: boolean onOpenChange: (open: boolean) => void /** Fired after a verifikat is created/saved as draft. */ onCreated: () => void /** When set, the form is pre-filled from a copied verifikat. */ copyPrefill?: CopyPrefill | null /** True while the copy source is being fetched. */ isLoading?: boolean } /** * "Ny verifikat" as a modal: the dialog you type a manual voucher into, * instead of an inline tab. Wraps the standalone JournalEntryForm; the form's * own review/confirm dialogs stack on top of this one. */ export default function NewJournalEntryDialog({ open, onOpenChange, onCreated, copyPrefill, isLoading, }: Props) { const t = useTranslations('bookkeeping') const { openAgentSheet, identity } = useAgentSheet() return ( e.preventDefault()} onPointerDownOutside={(e) => e.preventDefault()} onInteractOutside={(e) => e.preventDefault()} > {t('new_entry_dialog_title')} {identity.isVerified && !copyPrefill && ( // Hand off to the assistant: it reads the underlag (the figures the // user often can't see), suggests accounts, and stages a balanced // verifikat to approve: no copy-paste. Close the modal first so its // focus trap doesn't fight the (non-modal) agent sheet. )} {isLoading ? (
{t('loading_source_voucher')}
) : ( <> {copyPrefill && (

{t('copy_banner_title', { label: copyPrefill.sourceVoucherLabel || t('copy_banner_unknown_label'), })}

{t('copy_banner_body')}

)} )}
) }