eazygit 0.5.1

A fast TUI for Git with staging, conflicts, rebase, and palette-first UX
Documentation
use crate::app::{actions::Action, state::AppState};

pub fn handle_log_menu(mut state: AppState, action: &Action) -> Option<AppState> {
    match action {
        Action::ShowLogActionMenu(hash) => {
            state.log_action_menu = true;
            state.log_action_selected = 0;
            state.log_action_commit_hash = Some(hash.clone());
        }
        Action::HideLogActionMenu => {
            state.log_action_menu = false;
            state.log_action_selected = 0;
            state.log_action_commit_hash = None;
        }
        Action::LogActionMenuUp => {
            if state.log_action_selected > 0 {
                state.log_action_selected -= 1;
            }
        }
        Action::LogActionMenuDown => {
            // Get available actions to determine max index
            use crate::app::actions::LogAction;
            let mut actions = vec![
                LogAction::ShowDetail,
                LogAction::CherryPick,
                LogAction::Revert,
                LogAction::ResetSoft,
                LogAction::ResetMixed,
                LogAction::ResetHard,
                LogAction::CreateBranch,
                LogAction::CreateTag,
            ];
            
            // Check if this is HEAD
            if let Some(hash) = &state.log_action_commit_hash {
                if let Some(first_commit) = state.commits.first() {
                    if first_commit.hash == *hash {
                        actions.insert(3, LogAction::Amend);
                    }
                }
            }
            
            let max_idx = actions.len().saturating_sub(1);
            if state.log_action_selected < max_idx {
                state.log_action_selected += 1;
            }
        }
        Action::ExecuteLogAction(_) => {
            // Handled by component layer, just reset generic state here.
            state.log_action_menu = false;
            state.log_action_selected = 0;
            state.log_action_commit_hash = None;
        }
        _ => return None,
    }
    Some(state)
}