use crate::tui::ecs::events::Message;
use crate::tui::ecs::resources::MouseButton;
use crate::tui::ecs::world::World;
use crate::tui::key_code::KeyCode;

pub trait State {
    fn title(&self) -> &str {
        "TUI"
    }

    fn initialize(&mut self, _world: &mut World) {}

    fn run_systems(&mut self, _world: &mut World) {}

    fn handle_event(&mut self, _world: &mut World, _message: &Message) {}

    fn on_keyboard_input(&mut self, _world: &mut World, _key: KeyCode, _pressed: bool) {}

    fn on_mouse_input(
        &mut self,
        _world: &mut World,
        _button: MouseButton,
        _column: u16,
        _row: u16,
        _pressed: bool,
    ) {
    }

    fn on_mouse_move(&mut self, _world: &mut World, _column: u16, _row: u16) {}

    fn next_state(&mut self, _world: &mut World) -> Option<Box<dyn State>> {
        None
    }
}

#[cfg(feature = "tui")]
pub fn launch(state: Box<dyn State>) -> Result<(), Box<dyn std::error::Error>> {
    crate::tui::backend::run::launch(state)
}
