'use client' import { useState } from 'react' import { debugProps } from '@/lib/debug' import { AlertDialog, AlertDialogContent, AlertDialogHeader, AlertDialogTitle, AlertDialogDescription, AlertDialogFooter, AlertDialogAction, AlertDialogCancel, } from '@/components/ui/alert-dialog' interface DirtyCloseGuardProps { isDirty: boolean onConfirm: () => void children: (attemptClose: () => void) => React.ReactNode } export function DirtyCloseGuard({ isDirty, onConfirm, children }: DirtyCloseGuardProps) { const [open, setOpen] = useState(false) function attemptClose() { if (isDirty) { setOpen(true) } else { onConfirm() } } return ( <> {children(attemptClose)} Wijzigingen niet opgeslagen Wil je de wijzigingen weggooien? setOpen(false)}> Blijven { setOpen(false); onConfirm() }} > Weggooien ) }