class_name PauseMain extends VBoxContainer

signal resumeRequested
signal settingsRequested
signal mainMenuRequested
signal quitRequested

@export var btnResume:Button
@export var btnSettings:Button
@export var btnMainMenu:Button
@export var btnQuit:Button
@export var mainButtons:VBoxContainer
@export var confirmQuit:VBoxContainer
@export var btnQuitConfirm:Button
@export var btnQuitCancel:Button

func _ready() -> void:
  visible = false
  btnResume.pressed.connect(resumeRequested.emit)
  btnSettings.pressed.connect(settingsRequested.emit)
  btnMainMenu.pressed.connect(mainMenuRequested.emit)
  btnQuit.pressed.connect(_showConfirm)
  btnQuitConfirm.pressed.connect(quitRequested.emit)
  btnQuitCancel.pressed.connect(cancelConfirm)

func _showConfirm() -> void:
  mainButtons.visible = false
  confirmQuit.visible = true
  btnQuitCancel.grab_focus()

func cancelConfirm() -> void:
  mainButtons.visible = true
  confirmQuit.visible = false
  btnQuit.grab_focus()

func isConfirming() -> bool:
  return confirmQuit.visible

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

func close() -> void:
  visible = false

func isOpen() -> bool:
  return visible
