package main

import rl "vendor:raylib"
import "core:math/ease"


Menu_Buttons :: enum {
	START,
	TUTORIAL,
	KEYBOARD_ONLY,
	FULLSCREEN,
	EXIT
}

menu_strings := [Menu_Buttons]cstring {
	.START = "Старт",
	.TUTORIAL = "Обучение",
	.KEYBOARD_ONLY = "Только клавиатура",
	.FULLSCREEN = "Полный экран",
	.EXIT = "Выход"
}

menu_items := [Menu_Buttons]MenuItem {
	.START = {text = menu_strings[.START]},
	.TUTORIAL = {text = menu_strings[.TUTORIAL], param = &NeedTutorial, type = MenuItemType.BOOL},
	.KEYBOARD_ONLY = {text = menu_strings[.KEYBOARD_ONLY], param = &KeyboardOnly, type = MenuItemType.BOOL},
	.FULLSCREEN = {text = menu_strings[.FULLSCREEN], param = &Fullscreen, type = MenuItemType.BOOL},
	.EXIT = {text = menu_strings[.EXIT]}
}

Menu :: struct {
	using state: GameState,

	list: MenuList(Menu_Buttons),

}

menu_init :: proc(prev: ^GameState = nil) -> ^GameState {
	state := new(Menu)
	state.variant = state
	state.list = MenuList(Menu_Buttons){
		state = state,
		position = {100, WSize.y / 2},
		line_size = 60,
		font_size = 48,
		elements = &menu_items,
		menu_pressed = menu_button_pressed,
		background = rl.Color{50, 10, 110, 0}
	}
	state.update = menu_update
	state.draw = menu_draw 
	state.free = menu_free
	state.previous = prev

	return state
}

menu_update :: proc(state: ^GameState, delta: f32) {
	menu := transmute(^Menu)state
	menu.list.position.y = WSize.y / 2
	
	menu_list_update(&menu.list)
}

menu_button_pressed :: proc(state: ^GameState, el: Menu_Buttons) {
	switch el  {
		case .START:
			game := transmute(^Game)state.previous
			change_track(Res.Music.First)
			stack_pop()
			return
		case .TUTORIAL:
			NeedTutorial = !NeedTutorial
		case .KEYBOARD_ONLY:
			KeyboardOnly = !KeyboardOnly
			NeedTutorial = true
		case .FULLSCREEN:
			toggle_fullscreen()
//			Fullscreen = rl.IsWindowFullscreen()

		case .EXIT:
			WindowShouldExit = true
			return
	}
}

menu_draw :: proc(state: ^GameState) {
	menu := transmute(^Menu)state

    menu.previous.draw(menu.previous)

	TitleFontSize :: 96
	TitleSpacing :: 3
	TitleText :: "Ragnarøkkr"
	TitleSize := rl.MeasureTextEx(Res.Fonts.Title, TitleText, TitleFontSize, TitleSpacing)
	rl.DrawTextPro(Res.Fonts.Title, TitleText, {WSize.x - 50, 50}, {TitleSize.x, 0}, 0, 96, 3, rl.WHITE)

	menu_list_draw(&menu.list)

}

menu_free :: proc(state: ^GameState) {
	//free(state)
}
