"use client"; import { useState, useEffect } from "react"; import { Modal } from "@/app/_components/GlobalComponents/UIElements/Modal"; import { Button } from "@/app/_components/GlobalComponents/UIElements/Button"; import { UploadIcon, TrashIcon, CalendarIcon, UserIcon, DownloadIcon, ArrowsClockwiseIcon, CheckIcon, } from "@phosphor-icons/react"; import { useTranslations } from "next-intl"; import { CronJob } from "@/app/_utils/cronjob-utils"; import { unwrapCommand } from "@/app/_utils/wrapper-utils-client"; import { copyToClipboard } from "@/app/_utils/global-utils"; interface BackupFile { filename: string; job: CronJob; backedUpAt: string; } interface RestoreBackupModalProps { isOpen: boolean; onClose: () => void; backups: BackupFile[]; onRestore: (filename: string) => void; onRestoreAll: () => void; onBackupAll: () => void; onDelete: (filename: string) => void; onRefresh: () => void; } export const RestoreBackupModal = ({ isOpen, onClose, backups, onRestore, onRestoreAll, onBackupAll, onDelete, onRefresh, }: RestoreBackupModalProps) => { const t = useTranslations(); const [deletingFilename, setDeletingFilename] = useState(null); const [commandCopied, setCommandCopied] = useState(null); useEffect(() => { if (isOpen) { onRefresh(); } }, [isOpen]); const handleRestoreAll = () => { if (window.confirm(t("cronjobs.confirmRestoreAll"))) { onRestoreAll(); } }; const handleDelete = async (filename: string) => { if (window.confirm(t("cronjobs.confirmDeleteBackup"))) { setDeletingFilename(filename); await onDelete(filename); setDeletingFilename(null); onRefresh(); } }; const formatDate = (dateString: string) => { try { const date = new Date(dateString); return date.toLocaleString(); } catch { return dateString; } }; return (
{backups.length > 0 && ( )}
{backups.length === 0 ? (

{t("cronjobs.noBackupsFound")}

) : (
{backups.map((backup) => (
{backup.job.schedule}
{commandCopied === backup.filename && ( )}
 {
                          e.stopPropagation();
                          copyToClipboard(unwrapCommand(backup.job.command));
                          setCommandCopied(backup.filename);
                          setTimeout(() => setCommandCopied(null), 3000);
                        }}
                        className="flex-1 cursor-pointer overflow-hidden text-sm font-medium terminal-font bg-background1 px-2 py-1 ascii-border truncate"
                        title={unwrapCommand(backup.job.command)}
                      >
                        {unwrapCommand(backup.job.command)}
                      
{backup.job.user}
{formatDate(backup.backedUpAt)}
{backup.job.comment && (

{backup.job.comment}

)}
))}
)}

{t("cronjobs.availableBackups")}: {backups.length}

); };