use std::time::Duration;

use ratatui::crossterm::event;
use thecockpit::app::App;

fn main() {
    let mut terminal = ratatui::init();
    let mut app = App::new();

    loop {
        terminal.draw(|frame| app.draw(frame)).unwrap();

        if event::poll(Duration::from_secs(0)).unwrap() {
            match event::read().unwrap() {
                event::Event::Key(event::KeyEvent {
                    code: event::KeyCode::Char('q'),
                    ..
                }) => break,
                event::Event::Key(event::KeyEvent {
                    code: event::KeyCode::Left,
                    ..
                }) => app.prev_tab(),
                event::Event::Key(event::KeyEvent {
                    code: event::KeyCode::Right,
                    ..
                }) => app.next_tab(),
                event::Event::Key(event::KeyEvent {
                    code: event::KeyCode::Char(c),
                    ..
                }) => app.add_char_to_number_guess(c),
                _ => {}
            }
        }
    }

    ratatui::restore();
}
