import { ConfirmDialog } from '@/components/confirm-dialog';

type DeleteConfirmDialogProps<T> = {
    target: T | null;
    onOpenChange: (open: boolean) => void;
    title: string;
    description?: string | ((target: T) => string);
    confirmLabel?: string;
    variant?: 'default' | 'destructive';
    onConfirm: () => void;
};

export function DeleteConfirmDialog<T>({
    target,
    onOpenChange,
    title,
    description,
    confirmLabel = 'Hapus',
    variant,
    onConfirm,
}: DeleteConfirmDialogProps<T>) {
    return (
        <ConfirmDialog
            open={target !== null}
            onOpenChange={onOpenChange}
            title={title}
            description={
                typeof description === 'function' && target
                    ? description(target)
                    : typeof description === 'string'
                        ? description
                        : ''
            }
            confirmLabel={confirmLabel}
            variant={variant}
            onConfirm={onConfirm}
        />
    );
}
