// Package worktree provides CLI commands for managing amux worktrees.
package worktree

import (
	"github.com/spf13/cobra"
)

var (
	// Create flags
	createBaseBranch  string
	createBranch      string // Create new branch with specified name
	createCheckout    string // Checkout existing branch
	createDescription string
	createNoHooks     bool

	// List flags
	listOneline bool

	// Prune flags
	pruneDays   int
	pruneDryRun bool

	// Remove flags
	removeForce   bool
	removeNoHooks bool
)

var worktreeCmd = &cobra.Command{
	Use:     "worktree",
	Aliases: []string{"wt"},
	Short:   "Manage Amux worktrees",
	Long:    "Create, list, and remove isolated git worktrees",
}

func init() {
	// Add subcommands
	worktreeCmd.AddCommand(createWorktreeCmd)
	worktreeCmd.AddCommand(listWorktreeCmd)
	worktreeCmd.AddCommand(showWorktreeCmd)
	worktreeCmd.AddCommand(removeWorktreeCmd)
	worktreeCmd.AddCommand(pruneWorktreeCmd)
	worktreeCmd.AddCommand(cdWorktreeCmd)

	// Create command flags
	createWorktreeCmd.Flags().StringVar(&createBaseBranch, "base", "", "Base branch for new branches")
	createWorktreeCmd.Flags().StringVarP(&createBranch, "branch", "b", "", "Create new branch with specified name")
	createWorktreeCmd.Flags().StringVarP(&createCheckout, "checkout", "c", "", "Use existing branch")
	createWorktreeCmd.Flags().StringVarP(&createDescription, "description", "d", "", "Description of the worktree")
	createWorktreeCmd.Flags().BoolVar(&createNoHooks, "no-hooks", false, "Skip running hooks for this operation")

	// List command flags
	listWorktreeCmd.Flags().BoolVar(&listOneline, "oneline", false, "Show one worktree per line (for use with fzf)")

	// Prune command flags
	pruneWorktreeCmd.Flags().IntVarP(&pruneDays, "days", "d", 7, "Remove worktrees idle for more than N days")
	pruneWorktreeCmd.Flags().BoolVar(&pruneDryRun, "dry-run", false, "Show what would be removed without removing")

	// Remove command flags
	removeWorktreeCmd.Flags().BoolVarP(&removeForce, "force", "f", false, "Force removal without confirmation")
	removeWorktreeCmd.Flags().BoolVar(&removeNoHooks, "no-hooks", false, "Skip running hooks for this operation")
}

// Command returns the worktree command
func Command() *cobra.Command {
	return worktreeCmd
}
