class_name PauseMenu extends Control

@export var MAIN:PauseMain
@export var settingsPanel:PauseSettings

func _ready() -> void:
  close()
  MAIN.resumeRequested.connect(close)
  MAIN.settingsRequested.connect(_openSettings)
  MAIN.quitRequested.connect(func(): get_tree().quit())

func isOpen() -> bool:
  return visible

func open() -> void:
  visible = true
  get_tree().paused = true
  MAIN.open()

func close() -> void:
  get_tree().paused = false
  visible = false
  MAIN.close()
  settingsPanel.close()

func _openSettings() -> void:
  MAIN.close()
  settingsPanel.open()

func _unhandled_input(event:InputEvent) -> void:
  if !visible:
    return
  if event.is_action_pressed("ui_cancel"):
    if settingsPanel.isOpen():
      settingsPanel.close()
      MAIN.open()
    else:
      close()
    get_viewport().set_input_as_handled()
