use abi::io::KeyboardKey as Key;

macro_rules! table {
    {
        $vis:vis static $name:ident:
        [$ty:ty; $size:expr; $default:expr] =
        [ $( $index:literal => $value:expr ),* $(,)? ];
    } => {
        $vis static $name: [$ty; $size] = const {
            let mut array = [$default; $size];

            $(
                array[$index] = $value;
            )*

            array
        };
    };
}

table! {
    pub static CODE_SET_1_00: [Key; 128; Key::Unknown] = [
        0x01 => Key::Escape,
        0x02 => Key::Char(b'1'),
        0x03 => Key::Char(b'2'),

        0x04 => Key::Char(b'3'),
        0x05 => Key::Char(b'4'),
        0x06 => Key::Char(b'5'),
        0x07 => Key::Char(b'6'),

        0x08 => Key::Char(b'7'),
        0x09 => Key::Char(b'8'),
        0x0A => Key::Char(b'9'),
        0x0B => Key::Char(b'0'),

        0x0C => Key::Char(b'-'),
        0x0D => Key::Char(b'='),
        0x0E => Key::Backspace,
        0x0F => Key::Tab,

        0x10 => Key::Char(b'q'),
        0x11 => Key::Char(b'w'),
        0x12 => Key::Char(b'e'),
        0x13 => Key::Char(b'r'),

        0x14 => Key::Char(b't'),
        0x15 => Key::Char(b'y'),
        0x16 => Key::Char(b'u'),
        0x17 => Key::Char(b'i'),

        0x18 => Key::Char(b'o'),
        0x19 => Key::Char(b'p'),
        0x1A => Key::Char(b'['),
        0x1B => Key::Char(b']'),

        0x1C => Key::Enter,
        0x1D => Key::LControl,
        0x1E => Key::Char(b'a'),
        0x1F => Key::Char(b's'),

        0x20 => Key::Char(b'd'),
        0x21 => Key::Char(b'f'),
        0x22 => Key::Char(b'g'),
        0x23 => Key::Char(b'h'),

        0x24 => Key::Char(b'j'),
        0x25 => Key::Char(b'k'),
        0x26 => Key::Char(b'l'),
        0x27 => Key::Char(b';'),

        0x28 => Key::Char(b'\''),
        0x29 => Key::Char(b'`'),
        0x2A => Key::LShift,
        0x2B => Key::Char(b'\\'),

        0x2C => Key::Char(b'z'),
        0x2D => Key::Char(b'x'),
        0x2E => Key::Char(b'c'),
        0x2F => Key::Char(b'v'),

        0x30 => Key::Char(b'b'),
        0x31 => Key::Char(b'n'),
        0x32 => Key::Char(b'm'),
        0x33 => Key::Char(b','),

        0x34 => Key::Char(b'.'),
        0x35 => Key::Char(b'/'),
        0x36 => Key::RShift,
        // 0x37 => Key::KeypadMul,

        0x38 => Key::LAlt,
        0x39 => Key::Char(b' '),
        0x3A => Key::CapsLock,
        0x3B => Key::F(1),

        0x3C => Key::F(2),
        0x3D => Key::F(3),
        0x3E => Key::F(4),
        0x3F => Key::F(5),

        0x40 => Key::F(6),
        0x41 => Key::F(7),
        0x42 => Key::F(8),
        0x43 => Key::F(9),

        0x44 => Key::F(10),
        // 0x45 => Key::NumLock,
        // 0x46 => Key::ScrollLock,
        // 0x47 => Key::Keypad7,

        // 0x48 => Key::Keypad8,
        // 0x49 => Key::Keypad9,
        // 0x4A => Key::KeypadMinus,
        // 0x4B => Key::Keypad4,

        // 0x4C => Key::Keypad5,
        // 0x4D => Key::Keypad6,
        // 0x4E => Key::KeypadPlus,
        // 0x4F => Key::Keypad1,

        // 0x50 => Key::Keypad2,
        // 0x51 => Key::Keypad3,
        // 0x52 => Key::Keypad0,
        // 0x53 => Key::KeypadPeriod,

        0x57 => Key::F(11),

        0x58 => Key::F(12),
    ];
}

table! {
    pub static CODE_SET_1_E0: [Key; 128; Key::Unknown] = [
        0x1D => Key::RControl,
        0x38 => Key::RAlt,
        0x47 => Key::Home,
        0x48 => Key::Up,
        0x49 => Key::PageUp,
        0x4B => Key::Left,
        0x4D => Key::Right,
        0x4F => Key::End,
        0x50 => Key::Down,
        0x51 => Key::PageDown,
        0x52 => Key::Insert,
        0x53 => Key::Delete,
    ];
}
