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

pub fn reduce(mut state: AppState, action: &Action) -> Option<AppState> {
    match action {
        Action::ShowPalette => {
            state.command_palette = true;
            state.palette_input.clear();
            state.palette_selected = 0;
        }
        Action::HidePalette => {
            state.command_palette = false;
            state.palette_input.clear();
        }
        Action::SetPaletteInput(input) => {
            state.palette_input = input.clone();
            state.palette_selected = 0;
        }
        Action::PaletteUp => {
            if state.palette_selected > 0 {
                state.palette_selected -= 1;
            }
        }
        Action::PaletteDown => {
            // Will be bounded when rendering filtered list
            state.palette_selected += 1;
        }
        _ => return None,
    }
    Some(state)
}
