package client.window;

import static org.lwjgl.glfw.GLFW.*;

public enum Keysym implements Input {
	N0('0', GLFW_KEY_0),
	N1('1', GLFW_KEY_1),
	N2('2', GLFW_KEY_2),
	N3('3', GLFW_KEY_3),
	N4('4', GLFW_KEY_4),
	N5('5', GLFW_KEY_5),
	N6('6', GLFW_KEY_6),
	N7('7', GLFW_KEY_7),
	N8('8', GLFW_KEY_8),
	N9('9', GLFW_KEY_9),

	A('a', GLFW_KEY_A),
	B('b', GLFW_KEY_B),
	C('c', GLFW_KEY_C),
	D('d', GLFW_KEY_D),
	E('e', GLFW_KEY_E),
	F('f', GLFW_KEY_F),
	G('g', GLFW_KEY_G),
	H('h', GLFW_KEY_H),
	I('i', GLFW_KEY_I),
	J('j', GLFW_KEY_J),
	K('k', GLFW_KEY_K),
	L('l', GLFW_KEY_L),
	M('m', GLFW_KEY_M),
	N('n', GLFW_KEY_N),
	O('o', GLFW_KEY_O),
	P('p', GLFW_KEY_P),
	Q('q', GLFW_KEY_Q),
	R('r', GLFW_KEY_R),
	S('s', GLFW_KEY_S),
	T('t', GLFW_KEY_T),
	U('u', GLFW_KEY_U),
	V('v', GLFW_KEY_V),
	W('w', GLFW_KEY_W),
	X('x', GLFW_KEY_X),
	Y('y', GLFW_KEY_Z),
	Z('z', GLFW_KEY_Y),

	F1("f1", "F1", GLFW_KEY_F1),
	F2("f2", "F2", GLFW_KEY_F2),
	F3("f3", "F3", GLFW_KEY_F3),
	F4("f4", "F4", GLFW_KEY_F4),
	F5("f5", "F5", GLFW_KEY_F5),
	F6("f6", "F6", GLFW_KEY_F6),
	F7("f7", "F7", GLFW_KEY_F7),
	F8("f8", "F8", GLFW_KEY_F8),
	F9("f9", "F9", GLFW_KEY_F9),
	F10("f10", "F10", GLFW_KEY_F10),
	F11("f11", "F11", GLFW_KEY_F11),
	F12("f12", "F12", GLFW_KEY_F12),

	KP_0("kp0", "Num 0", GLFW_KEY_KP_0),
	KP_1("kp1", "Num 1", GLFW_KEY_KP_1),
	KP_2("kp2", "Num 2", GLFW_KEY_KP_2),
	KP_3("kp3", "Num 3", GLFW_KEY_KP_3),
	KP_4("kp4", "Num 4", GLFW_KEY_KP_4),
	KP_5("kp5", "Num 5", GLFW_KEY_KP_5),
	KP_6("kp6", "Num 6", GLFW_KEY_KP_6),
	KP_7("kp7", "Num 7", GLFW_KEY_KP_7),
	KP_8("kp8", "Num 8", GLFW_KEY_KP_8),
	KP_9("kp9", "Num 9", GLFW_KEY_KP_9),

	SPACE("space", "Leertaste", GLFW_KEY_SPACE),
	CIRCUMFLEX('^', GLFW_KEY_GRAVE_ACCENT),
	SHARP_S('ß', GLFW_KEY_MINUS),
	ACUTE('´', GLFW_KEY_EQUAL),
	UE('ü', GLFW_KEY_LEFT_BRACKET),
	PLUS('+', GLFW_KEY_RIGHT_BRACKET),
	OE('ö', GLFW_KEY_SEMICOLON),
	AE('ä', GLFW_KEY_APOSTROPHE),
	NUMBER_SIGN('#', GLFW_KEY_BACKSLASH),
	LESS_THAN('<', GLFW_KEY_WORLD_1),
	COMMA(',', GLFW_KEY_COMMA),
	PERIOD('.', GLFW_KEY_PERIOD),
	HYPHEN('-', GLFW_KEY_SLASH),

	KP_DECIMAL("kp.", "Num .", GLFW_KEY_KP_DECIMAL),
	KP_DIVIDE("kp/", "Num /", GLFW_KEY_KP_DIVIDE),
	KP_MULTIPLY("kp*", "Num *", GLFW_KEY_KP_MULTIPLY),
	KP_SUBTRACT("kp-", "Num -", GLFW_KEY_KP_SUBTRACT),
	KP_ADD("kp+", "Num +", GLFW_KEY_KP_ADD),
	KP_ENTER("enter", "Num Enter", GLFW_KEY_KP_ENTER),
	KP_EQUAL("kp=", "Num =", GLFW_KEY_KP_EQUAL),

	CAPS_LOCK("caps", "Feststellen", GLFW_KEY_CAPS_LOCK),
	SCROLL_LOCK("scroll", "Scroll Lock", GLFW_KEY_SCROLL_LOCK),
	NUM_LOCK("num", "Num Lock", GLFW_KEY_NUM_LOCK),

	ESCAPE("esc", "Esc", GLFW_KEY_ESCAPE),
	RETURN("return", "Enter", GLFW_KEY_ENTER),
	TAB("tab", "Tab", GLFW_KEY_TAB),
	BACKSPACE("bksp", "Rücktaste", GLFW_KEY_BACKSPACE),
	INSERT("ins", "Einfg", GLFW_KEY_INSERT),
	DELETE("del", "Entf", GLFW_KEY_DELETE),
	RIGHT("right", "Pfeil rechts", GLFW_KEY_RIGHT),
	LEFT("left", "Pfeil links", GLFW_KEY_LEFT),
	DOWN("down", "Pfeil unten", GLFW_KEY_DOWN),
	UP("up", "Pfeil oben", GLFW_KEY_UP),
	PAGE_UP("pgup", "Bild auf", GLFW_KEY_PAGE_UP),
	PAGE_DOWN("pgdn", "Bild ab", GLFW_KEY_PAGE_DOWN),
	HOME("home", "Pos1", GLFW_KEY_HOME),
	END("end", "Ende", GLFW_KEY_END),
	PRINT_SCREEN("print", "Druck", GLFW_KEY_PRINT_SCREEN),
	PAUSE("pause", "Pause", GLFW_KEY_PAUSE),
	LEFT_SHIFT("lshift", "Umschalt links", GLFW_KEY_LEFT_SHIFT),
	LEFT_CONTROL("lctrl", "Strg links", GLFW_KEY_LEFT_CONTROL),
	ALT("alt", "Alt", GLFW_KEY_LEFT_ALT),
	LEFT_SUPER("lsuper", "Super links", GLFW_KEY_LEFT_SUPER),
	RIGHT_SHIFT("rshift", "Umschalt rechts", GLFW_KEY_RIGHT_SHIFT),
	RIGHT_CONTROL("rctrl", "Strg rechts", GLFW_KEY_RIGHT_CONTROL),
	ALT_GRAPH("altgr", "Alt Gr", GLFW_KEY_RIGHT_ALT),
	RIGHT_SUPER("rsuper", "Super rechts", GLFW_KEY_RIGHT_SUPER),
	MENU("menu", "Menü", GLFW_KEY_MENU);

	private static final Keysym[] KEYS = new Keysym[GLFW_KEY_LAST];
	
	private final String id;
	private final String name;
	private final int code;
	
	static {
		for(Keysym key : values()) {
			KEYS[key.code - 1] = key;
		}
	}
	
	public static Keysym getForCode(int code) {
		return code > 0 && code <= KEYS.length ? KEYS[code - 1] : null;
	}
	
	private Keysym(String id, String name, int code) {
		this.id = id;
		this.name = name;
		this.code = code;
	}
	
	private Keysym(char character, int code) {
		this(Character.toString(character), "<" + Character.toUpperCase(character) + ">", code);
	}

	public String getName() {
		return this.id;
	}

	public String getDisplay() {
		return this.name;
	}

	public boolean read() {
		return Window.getKey(this.code);
	}
}
