extends Control

func _ready() -> void:
	process_mode = Node.PROCESS_MODE_ALWAYS
	set_anchors_preset(Control.PRESET_FULL_RECT)

	# Semi-transparent background
	var bg := ColorRect.new()
	bg.set_anchors_preset(Control.PRESET_FULL_RECT)
	bg.color = Color(0, 0, 0, 0.7)
	add_child(bg)

	# Center VBox
	var vbox := VBoxContainer.new()
	vbox.set_anchors_preset(Control.PRESET_CENTER)
	vbox.add_theme_constant_override("separation", 16)
	vbox.set_offset(SIDE_LEFT, -120)
	vbox.set_offset(SIDE_RIGHT, 120)
	vbox.set_offset(SIDE_TOP, -120)
	vbox.set_offset(SIDE_BOTTOM, 120)
	add_child(vbox)

	var title := Label.new()
	title.text = "PAUSE"
	title.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
	title.add_theme_font_size_override("font_size", 48)
	vbox.add_child(title)

	var btn_resume := Button.new()
	btn_resume.text = "Reprendre"
	btn_resume.pressed.connect(_on_resume)
	vbox.add_child(btn_resume)

	var btn_menu := Button.new()
	btn_menu.text = "Menu principal"
	btn_menu.pressed.connect(_on_main_menu)
	vbox.add_child(btn_menu)

	var btn_quit := Button.new()
	btn_quit.text = "Quitter"
	btn_quit.pressed.connect(_on_quit)
	vbox.add_child(btn_quit)


func show_pause() -> void:
	show()
	get_tree().paused = true
	Input.mouse_mode = Input.MOUSE_MODE_VISIBLE


func hide_pause() -> void:
	hide()
	get_tree().paused = false
	Input.mouse_mode = Input.MOUSE_MODE_CAPTURED


func _on_resume() -> void:
	hide_pause()


func _on_main_menu() -> void:
	get_tree().paused = false
	get_tree().change_scene_to_file("res://scenes/MainMenu.tscn")


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