extends Control

@export var play_scene_path: String

# Node references
@onready var play_button = $MarginContainer/HBoxContainer/VBoxContainer/PlayBtn
@onready var about_button = $MarginContainer/HBoxContainer/VBoxContainer/AboutBtn
@onready var quit_button = $MarginContainer/HBoxContainer/VBoxContainer/QuitBtn
@onready var about_dialog = $AboutDialog   # Already in scene

var quit_dialog: ConfirmationDialog

func _ready():
	# Connect button signals
	play_button.pressed.connect(_on_play_pressed)
	play_button.mouse_entered.connect(_on_button_hovered)
	
	about_button.pressed.connect(_on_about_pressed)
	about_button.mouse_entered.connect(_on_button_hovered)
	
	quit_button.pressed.connect(_on_quit_pressed)
	quit_button.mouse_entered.connect(_on_button_hovered)
	
	# Create Quit confirmation dialog dynamically
	quit_dialog = ConfirmationDialog.new()
	quit_dialog.title = "Quit Game"
	quit_dialog.dialog_text = "Are you sure you want to quit?"
	quit_dialog.confirmed.connect(_on_quit_confirmed)
	add_child(quit_dialog)
	
	# Play startup sound
	AudioManager.play("res://audio/gnossienne.ogg")

# Button click handlers
func _on_play_pressed():
	AudioManager.play("res://audio/button_click.ogg")
	if play_scene_path != "":
		get_tree().change_scene_to_file(play_scene_path)

func _on_about_pressed():
	AudioManager.play("res://audio/button_click.ogg")
	about_dialog.popup_centered()

func _on_quit_pressed():
	AudioManager.play("res://audio/button_click.ogg")
	quit_dialog.popup_centered()

func _on_quit_confirmed():
	AudioManager.play("res://audio/button_click.ogg")
	get_tree().quit()

# Hover sound handler
func _on_button_hovered():
	AudioManager.play("res://audio/button_hover.ogg")
