extends Control

var stageOne = preload("res://Scenes/Stages/stage1.tscn")
@onready var WindowMode = $OptionsMenu/Display_Options_0/Window_Mode
@onready var SelectSFX = $SelectSFX
@onready var ConfirmSFX = $ConfirmSFX
@onready var CancelSFX = $CancelSFX

const WINDOW_MODE_ARRAY : Array[String]= [
	"Full-screen",
	"Window Mode",
	"Boderless Window",
	"Borderless Full-Screen"
]
var UI_ACTION_SFX : Dictionary
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
	UI_ACTION_SFX = {
		"ui_down": $SelectSFX,
		"ui_up": $SelectSFX,
		"ui_left": $SelectSFX,
		"ui_right": $SelectSFX,
		"ui_accept": $ConfirmSFX,
		#"ui_cancel": $CancelSFX,
	}
	add_window_mode_items()
	$StartMenu/Start_Button.grab_focus.call_deferred()
	$StartMenu/Label.modulate.a = 0.0 
	var tween = create_tween()
	tween.tween_property($StartMenu/Label, "modulate:a", 1.0, 2)
	
	Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
	pass # Replace with function body.


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
	for action in UI_ACTION_SFX.keys():
		if Input.is_action_just_pressed(action):
			print(UI_ACTION_SFX[action])
			UI_ACTION_SFX[action].play()
			pass
	pass


func _on_start_button_pressed() -> void:
	get_tree().change_scene_to_packed(stageOne)
	pass # Replace with function body.


func _on_options_button_pressed() -> void:
	$OptionsMenu/TabBar.grab_focus()
	$OptionsMenu.visible = true
	$StartMenu.visible = false
	pass # Replace with function body.


func _on_quit_button_pressed() -> void:
	get_tree().quit()


func _on_return_button_pressed() -> void:
	$OptionsMenu.visible = false
	$StartMenu.visible = true
	pass # Replace with function body.


func add_window_mode_items() -> void:
	for window_mode in WINDOW_MODE_ARRAY:
		WindowMode.add_item(window_mode)
	
func _on_window_mode_item_selected(index: int) -> void:
	match index:
		0: #Full-Screen
			DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_FULLSCREEN)
			DisplayServer.window_set_flag(DisplayServer.WINDOW_FLAG_BORDERLESS, false)
		1: #Window Mode
			DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_WINDOWED)
			DisplayServer.window_set_flag(DisplayServer.WINDOW_FLAG_BORDERLESS, false)
		2: #Borderless Windowed
			DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_WINDOWED)
			DisplayServer.window_set_flag(DisplayServer.WINDOW_FLAG_BORDERLESS, true)
		3: #Borderless Fullscreen
			DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_FULLSCREEN)
			DisplayServer.window_set_flag(DisplayServer.WINDOW_FLAG_BORDERLESS, true)
