class_name PauseMain extends VBoxContainer

signal resumeRequested
signal settingsRequested

@export var btnResume:Button
@export var btnSettings:Button
@export var btnMainMenu:Button
@export var btnQuit:Button

func _ready() -> void:
  visible = false
  btnResume.pressed.connect(resumeRequested.emit)
  btnSettings.pressed.connect(settingsRequested.emit)
  btnMainMenu.pressed.connect(_showMainMenuConfirm)
  btnQuit.pressed.connect(_showQuitConfirm)
  UI.QUIT_DIALOG.closed.connect(_onQuitDialogClosed)
  UI.MAIN_MENU_DIALOG.closed.connect(_onMainMenuDialogClosed)

func _showQuitConfirm() -> void:
  UI.QUIT_DIALOG.open()

func _showMainMenuConfirm() -> void:
  UI.MAIN_MENU_DIALOG.open()

func _onQuitDialogClosed() -> void:
  if isOpen():
    btnQuit.grab_focus()

func _onMainMenuDialogClosed() -> void:
  if isOpen():
    btnMainMenu.grab_focus()

func open() -> void:
  visible = true
  btnResume.grab_focus()

func close() -> void:
  visible = false

func isOpen() -> bool:
  return visible
