eazygit 0.5.1

A fast TUI for Git with staging, conflicts, rebase, and palette-first UX
Documentation
#![allow(dead_code)]
//! Log action menu handling within commit reducer.

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

/// Logic for handling log action menu related actions.
pub fn handle(state: &mut AppState, action: &Action) -> bool {
    match action {
        Action::ShowLogActionMenu => {
            state.log_action_menu = true;
            state.log_action_selected = 0;
            // Track which commit hash this menu is for
            if let Some(entry) = state.commits.get(state.commit_selected) {
                state.log_action_commit_hash = Some(entry.hash.clone());
            }
            true
        }
        Action::HideLogActionMenu => {
            state.log_action_menu = false;
            state.log_action_commit_hash = None;
            true
        }
        Action::LogActionUp => {
            if state.log_action_selected > 0 {
                state.log_action_selected -= 1;
            }
            true
        }
        Action::LogActionDown => {
            // Max items depends on whether this is HEAD or not
            let is_head = state
                .commits
                .first()
                .map(|c| Some(&c.hash) == state.log_action_commit_hash.as_ref())
                .unwrap_or(false);
            let max_items = if is_head { 5 } else { 9 };
            if state.log_action_selected + 1 < max_items {
                state.log_action_selected += 1;
            }
            true
        }
        Action::ExecuteLogAction(log_action) => {
            // Reset menu state
            state.log_action_menu = false;
            state.log_action_selected = 0;
            
            // Handle specific log actions
            match log_action {
                LogAction::ShowDetail => {
                    if let Some(hash) = &state.log_action_commit_hash {
                        state.commit_detail = Some(hash.clone());
                    }
                }
                _ => {
                    // Other actions handled by command layer
                }
            }
            state.log_action_commit_hash = None;
            true
        }
        _ => false,
    }
}