"use client"; import React from "react"; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from "./ui/dialog"; import { Button } from "./ui/button"; import { AlertTriangle } from "lucide-react"; /** * Formats a list of files to be deleted, truncating if necessary. * @param files - Array of files with a `filename` property * @param maxVisible - Maximum number of items to show before truncating (default: 5) * @returns Formatted string with bullet points, truncated if needed */ export function formatFilesToDelete( files: Array<{ filename: string }>, maxVisible = 5, ): string { const visibleFiles = files.slice(0, maxVisible); const remainingCount = files.length - maxVisible; const fileList = visibleFiles.map((file) => `• ${file.filename}`).join("\n"); return remainingCount > 0 ? `${fileList}\n• ... and ${remainingCount} more document${ remainingCount > 1 ? "s" : "" }` : fileList; } interface DeleteConfirmationDialogProps { open: boolean; onOpenChange: (open: boolean) => void; title?: string; description?: string; confirmText?: string; cancelText?: string; onConfirm: () => void | Promise; isLoading?: boolean; variant?: "destructive" | "default"; } export const DeleteConfirmationDialog: React.FC< DeleteConfirmationDialogProps > = ({ open, onOpenChange, title = "Are you sure?", description = "This action cannot be undone.", confirmText = "Confirm", cancelText = "Cancel", onConfirm, isLoading = false, variant = "destructive", }) => { const handleConfirm = async () => { try { await onConfirm(); } finally { // Only close if not in loading state (let the parent handle this) if (!isLoading) { onOpenChange(false); } } }; return (
{variant === "destructive" && ( )} {title}
{description}
); };