use libcolors::{event::KeyModifiers, input::Key};

pub const KEY_UP: &[u8] = b"\x1B[A";
pub const KEY_DOWN: &[u8] = b"\x1B[B";
pub const KEY_RIGHT: &[u8] = b"\x1B[C";
pub const KEY_LEFT: &[u8] = b"\x1B[D";
pub const KEY_ENTER: &[u8] = b"\x0D";
pub const KEY_ESCAPE: &[u8] = b"\x1B";
pub const KEY_HOME: &[u8] = b"\x1B[H";
pub const KEY_END: &[u8] = b"\x1B[F";
pub const KEY_PAGEUP: &[u8] = b"\x1B[5~";
pub const KEY_PAGEDOWN: &[u8] = b"\x1B[6~";

pub fn map(modifier: KeyModifiers, key: Key) -> Option<&'static [u8]> {
    match (modifier, key) {
        (KeyModifiers::NONE, Key::Enter) => Some(KEY_ENTER),
        (KeyModifiers::NONE, Key::Escape) => Some(KEY_ESCAPE),
        (KeyModifiers::NONE, Key::Up) => Some(KEY_UP),
        (KeyModifiers::NONE, Key::Down) => Some(KEY_DOWN),
        (KeyModifiers::NONE, Key::Right) => Some(KEY_RIGHT),
        (KeyModifiers::NONE, Key::Left) => Some(KEY_LEFT),
        (KeyModifiers::NONE, Key::Home) => Some(KEY_HOME),
        (KeyModifiers::NONE, Key::End) => Some(KEY_END),
        (KeyModifiers::NONE, Key::PageUp) => Some(KEY_PAGEUP),
        (KeyModifiers::NONE, Key::PageDown) => Some(KEY_PAGEDOWN),
        _ => None,
    }
}
