class_name PauseMenu
extends Node

const ACTION_PAUSE: StringName = &"pause"

var can_pause: bool = true

@onready var pause_menu: MenuBase = $PauseMenu
@onready var options_menu: Control = $OptionsMenu


func _input(event: InputEvent) -> void:
	if event.is_action_pressed(ACTION_PAUSE):
		if options_menu.is_visible_in_tree():
			options_menu.hide()
			pause_menu.show()
		else:
			toggle_pause()


func set_paused(value: bool) -> void:
	if SceneFader.is_fading:
		return
	
	get_tree().paused = value
	pause_menu.visible = value
	
	Input.mouse_mode = Input.MOUSE_MODE_VISIBLE if value else Input.MOUSE_MODE_CAPTURED


func toggle_pause() -> void:
	if not can_pause or options_menu.is_visible():
		return
	
	set_paused(not get_tree().paused)


func _on_continue_button_pressed() -> void:
	set_paused(false)


func _on_main_menu_button_pressed() -> void:
	Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
	await SceneFader.load_to_path(GameGlobals.MAIN_MENU_PATH, true)


func _on_settings_button_pressed() -> void:
	pause_menu.hide()
	options_menu.show()
