# shellcheck shell=bash

cmd_delete_worktree() {
    if [ -z "${1-}" ]; then 
        err "Branch name required"
        echo "Usage: gw delete <branch>"
        return 1
    fi
    local branch_name="$1"
    git_require_repo || return 1
    
    local worktree_path; worktree_path="$(git_branch_to_worktree_path "$branch_name")"
    
    info "🗑️  Removing worktree and deleting branch '$branch_name'..."
    
    # Remove worktree if it exists
    if [[ -n "$worktree_path" ]] && [[ -d "$worktree_path" ]]; then
      git_remove_worktree "$worktree_path"
    fi
    
    # Delete branch if it exists
    if git_branch_exists "$branch_name"; then
      git_delete_branch "$branch_name"
    fi
    
    info "🧹 Done."
}
