use ratatui::crossterm::event::{KeyCode, KeyModifiers};
use crate::tui::{handlers::tab_navigation_handler, AppEvent};
use super::App;
pub fn app_event_handler(app: &mut App, event: AppEvent) {
match event {
AppEvent::Key(key) => match (key.code, key.modifiers) {
(KeyCode::Char('q'), KeyModifiers::NONE) => app.state.should_quit = true,
(
tab @ (KeyCode::Char('1')
| KeyCode::Char('2')
| KeyCode::Char('3')
| KeyCode::Char('4')
| KeyCode::Char('5')),
KeyModifiers::NONE,
) => tab_navigation_handler(app, tab),
(KeyCode::Down, KeyModifiers::NONE) => {
if let Some(s) = app.state.history_tab.history_table_state() {
let mut s = s.borrow_mut();
s.select_next();
}
}
(KeyCode::Up, KeyModifiers::NONE) => {
if let Some(s) = app.state.history_tab.history_table_state() {
let mut s = s.borrow_mut();
s.select_previous();
}
}
_ => {}
},
AppEvent::Error => {}
_ => {}
};
}