"use client"; import { useState } from "react"; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from "@/components/ui/dialog"; import { Button } from "@/components/ui/button"; import { Checkbox } from "@/components/ui/checkbox"; import { Label } from "@/components/ui/label"; import { Loader2, Trash2, AlertTriangle } from "lucide-react"; import { getElectronAPI } from "@/lib/electron"; import { toast } from "sonner"; interface WorktreeInfo { path: string; branch: string; isMain: boolean; hasChanges?: boolean; changedFilesCount?: number; } interface DeleteWorktreeDialogProps { open: boolean; onOpenChange: (open: boolean) => void; projectPath: string; worktree: WorktreeInfo | null; onDeleted: (deletedWorktree: WorktreeInfo, deletedBranch: boolean) => void; } export function DeleteWorktreeDialog({ open, onOpenChange, projectPath, worktree, onDeleted, }: DeleteWorktreeDialogProps) { const [deleteBranch, setDeleteBranch] = useState(false); const [isLoading, setIsLoading] = useState(false); const handleDelete = async () => { if (!worktree) return; setIsLoading(true); try { const api = getElectronAPI(); if (!api?.worktree?.delete) { toast.error("Worktree API not available"); return; } const result = await api.worktree.delete( projectPath, worktree.path, deleteBranch ); if (result.success) { toast.success(`Worktree deleted`, { description: deleteBranch ? `Branch "${worktree.branch}" was also deleted` : `Branch "${worktree.branch}" was kept`, }); onDeleted(worktree, deleteBranch); onOpenChange(false); setDeleteBranch(false); } else { toast.error("Failed to delete worktree", { description: result.error, }); } } catch (err) { toast.error("Failed to delete worktree", { description: err instanceof Error ? err.message : "Unknown error", }); } finally { setIsLoading(false); } }; if (!worktree) return null; return ( Delete Worktree Are you sure you want to delete the worktree for branch{" "} {worktree.branch} ? {worktree.hasChanges && (
This worktree has {worktree.changedFilesCount} uncommitted change(s). These will be lost if you proceed.
)}
setDeleteBranch(checked === true)} />
); }