// islands/DeleteLeaseButton.tsx import { useState } from "preact/hooks"; interface DeleteLeaseButtonProps { leaseId: string; propertyAddress: string; tenantName?: string; } export default function DeleteLeaseButton({ leaseId, propertyAddress, tenantName }: DeleteLeaseButtonProps) { const [isDeleting, setIsDeleting] = useState(false); const handleDelete = async () => { const tenantInfo = tenantName ? ` for ${tenantName}` : ""; const confirmed = confirm( `Are you sure you want to delete the lease for "${propertyAddress}"${tenantInfo}? This action cannot be undone.` ); if (!confirmed) return; setIsDeleting(true); try { const formData = new FormData(); formData.append('lease_id', leaseId); formData.append('sender', globalThis.location.pathname); const response = await fetch('/api/delete/lease', { method: 'POST', body: formData }); if (response.redirected) { globalThis.location.href = response.url; } else if (response.ok) { globalThis.location.reload(); } else { alert('Failed to delete lease. Please try again.'); } } catch (_error) { alert('Error deleting lease'); } finally { setIsDeleting(false); } }; return ( ); }