//! Navigation actions for status pane.
//!
//! Handles movement through the status file list (up, down, page up/down, top, bottom).

use crate::app::{actions::Action, state::AppState};

/// Handle navigation actions in the status pane.
pub fn handle_navigation(state: &mut AppState, action: &Action) -> bool {
    match action {
        Action::StatusUp => {
            if !state.status_entries.is_empty() {
                state.status_selected = state.status_selected.saturating_sub(1);
            }
            true
        }
        Action::StatusDown => {
            if !state.status_entries.is_empty() {
                let max_idx = state.status_entries.len().saturating_sub(1);
                state.status_selected = (state.status_selected + 1).min(max_idx);
            }
            true
        }
        Action::StatusPageUp => {
            if !state.status_entries.is_empty() {
                state.status_selected = state.status_selected.saturating_sub(10);
            }
            true
        }
        Action::StatusPageDown => {
            if !state.status_entries.is_empty() {
                let max_idx = state.status_entries.len().saturating_sub(1);
                state.status_selected = (state.status_selected + 10).min(max_idx);
            }
            true
        }
        Action::StatusTop => {
            if !state.status_entries.is_empty() {
                state.status_selected = 0;
            }
            true
        }
        Action::StatusBottom => {
            if !state.status_entries.is_empty() {
                state.status_selected = state.status_entries.len().saturating_sub(1);
            }
            true
        }
        _ => false,
    }
}

