import { useEffect, useRef, useState } from 'react'; import { Dialog, DialogContent, DialogHeader, DialogTitle } from '@/components/ui/Dialog'; export function ArchiveBacktestDialog({ name, archived, onConfirm, onClose, }: { name: string; archived: boolean; onConfirm: () => Promise; onClose: () => void; }) { const [saving, setSaving] = useState(false); const [error, setError] = useState(null); const pending = useRef(false); const active = useRef(true); const title = archived ? 'Archive backtest' : 'Restore backtest'; useEffect(() => { active.current = true; return () => { active.current = false; }; }, []); const confirm = async () => { if (pending.current) { return; } pending.current = true; setSaving(true); setError(null); try { await onConfirm(); if (active.current) { onClose(); } } catch (failure) { if (active.current) { setError(failure instanceof Error ? failure.message : 'Could not change archive status'); } } finally { pending.current = false; if (active.current) { setSaving(false); } } }; return ( { if (!open && !pending.current) { onClose(); } }} >
{title}

{name}

{archived ? 'Saved runs, results and dataset links remain available. Accepted runs can finish, recover or be cancelled. Restore the backtest to edit it or start new runs.' : 'Restore this backtest to the active list and allow editing and new runs.'}

{error && (

{error}

)} {saving && (

{archived ? 'Archiving...' : 'Restoring...'}

)}
); }