class_name MainMenu extends Control

@export var btnNewGame:Button
@export var btnSettings:Button
@export var settingsMenu:ClosableMenu
@export_file("*.tscn") var newGameScene:String

func _ready() -> void:
  btnNewGame.pressed.connect(onNewGamePressed)
  btnSettings.pressed.connect(onSettingsPressed)
  settingsMenu.opened.connect(_onSettingsOpened)
  settingsMenu.closed.connect(_onSettingsClosed)
  btnNewGame.grab_focus()

func _onSettingsOpened() -> void:
  # Move focus into the settings panel so the controller can navigate it.
  # The SettingsMenu grabs its own internal focus via _notification.
  pass

func _onSettingsClosed() -> void:
  btnSettings.grab_focus()

func _unhandled_input(event:InputEvent) -> void:
  if event.is_action_pressed("ui_cancel"):
    if settingsMenu.isOpen:
      settingsMenu.close()
      get_viewport().set_input_as_handled()

func onNewGamePressed() -> void:
  SCENE.setScene(SceneSingleton.SceneType.OVERWORLD)
  OVERWORLD.mapChange(newGameScene, "PlayerSpawnPoint")

func onSettingsPressed() -> void:
  settingsMenu.isOpen = true
