"use client"; import { useState } from "react"; import { useRouter } from "next/navigation"; export default function DeleteFileButton({ token, name }: { token: string; name: string }) { const router = useRouter(); const [loading, setLoading] = useState(false); async function handleDelete() { if (!confirm(`Delete "${name}"?\n\nThis permanently removes the file and cannot be undone.`)) return; setLoading(true); try { const res = await fetch(`/api/files/${token}`, { method: "DELETE" }); if (res.ok) { router.push("/browse"); router.refresh(); } else { const data = await res.json().catch(() => ({})) as { error?: string }; alert(data.error ?? `Delete failed (${res.status})`); } } catch { alert("Network error – could not delete file"); } finally { setLoading(false); } } return ( ); }