'use client' import { useState } from 'react' import { useTranslations } from 'next-intl' import { cn } from '@/lib/utils' import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from '@/components/ui/dialog' import { Button } from '@/components/ui/button' import { Loader2 } from 'lucide-react' interface ConfirmDialogProps { open: boolean onOpenChange: (open: boolean) => void title: string /** * Body text that DESCRIBES THE OUTCOME up front ("Bokförs som verifikat * A-217 med 1 250,00 kr ...") instead of the page commenting afterwards * (UI-migration convention 10). */ description?: React.ReactNode /** Optional richer body (e.g. a kontering preview) rendered below the description. */ children?: React.ReactNode confirmLabel: string cancelLabel?: string /** Await-able: the dialog shows a pending state until the promise settles. */ onConfirm: () => void | Promise /** Terracotta confirm for destructive outcomes (avvisa, makulera). */ destructive?: boolean } /** * Small centered confirmation dialog (min 460px on desktop): confirm before * acting, describing the outcome, rather than commenting after the fact. */ export function ConfirmDialog({ open, onOpenChange, title, description, children, confirmLabel, cancelLabel, onConfirm, destructive = false, }: ConfirmDialogProps) { const tCommon = useTranslations('common') const [pending, setPending] = useState(false) const handleConfirm = async () => { try { setPending(true) await onConfirm() onOpenChange(false) } finally { setPending(false) } } return ( !pending && onOpenChange(next)}> {title} {description && ( {description} )} {children} ) }