//! Application action types.
//!
//! Actions dispatched by input handling in the TUI application.

use std::path::PathBuf;

use crate::session::SessionId;

/// Actions that can be dispatched by input handling
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum AppAction {
    // Note: CreateSession removed (Ctrl-t deprecated)
    // Session creation now via WorkspacePopup only
    /// Terminate current session
    TerminateCurrentSession,
    /// Switch to session by index
    SwitchSession(usize),
    /// Switch to next session
    NextSession,
    /// Switch to previous session
    PrevSession,
    /// Show workspace popup (sessions + worktrees)
    ShowWorkspacePopup,
    /// Hide current popup
    HidePopup,
    /// Show quit confirmation
    ShowConfirmQuit,
    /// Confirm quit application
    ConfirmQuit,
    /// Send input to current session
    SendInput(Vec<u8>),
    /// Scroll terminal view
    Scroll(i32),
    /// Resize terminal
    ResizeTerminal(u16, u16),
    /// Select next item in popup
    SelectNext,
    /// Select previous item in popup
    SelectPrev,
    /// Confirm selection in popup (switch to session)
    ConfirmSelection,
    /// Toggle quit selection
    ToggleQuitSelection,
    /// Quit application
    Quit,

    // New workspace popup actions
    /// Create session with branch name (input field → create worktree + session)
    CreateSessionWithBranch(String),
    /// Adopt existing worktree (start session in it)
    AdoptWorktree {
        /// Path to worktree
        path: PathBuf,
    },
    /// Delete worktree without active session
    DeleteWorktree {
        /// Path to worktree
        path: PathBuf,
    },
    /// Git pull on worktree
    PullWorktree {
        /// Path to worktree
        path: PathBuf,
    },
    /// Input character for branch field
    InputChar(char),
    /// Delete char in input (backspace)
    InputBackspace,
    /// Move cursor left
    InputCursorLeft,
    /// Move cursor right
    InputCursorRight,
    /// Switch popup section (Tab)
    NextPopupSection,
    /// Switch popup section reverse (Shift-Tab)
    PrevPopupSection,
    /// Dismiss error popup
    DismissError,
    /// Cross-section navigation: next item (wraps `BranchInput` → `Sessions` → `Worktrees`)
    CrossSectionNext,
    /// Cross-section navigation: previous item (reverse wrap)
    CrossSectionPrev,
    /// Close terminated session (remove from list + cleanup worktree)
    CloseSession {
        /// Session ID to close
        id: SessionId,
    },
    /// Select issue from issues section
    SelectIssue {
        /// Issue number
        number: u32,
    },
    /// Select action choice from action popup
    SelectActionChoice {
        /// Choice index
        index: usize,
    },
    /// Toggle Yes/No in confirm permissions
    TogglePermissionsChoice,
    /// Confirm dangerous permissions (Y selected)
    ConfirmDangerousPermissions,
    /// Cancel and return to normal
    CancelIssueFlow,
}
