extends PanelContainer

const GENERAL = "GENERAL"
const SHOW_TUTORIAL = "SHOW_TUTORIAL"

@onready var show_tutorial = $MarginContainer/VBoxContainer/Tabs/General/GridContainer/TutorialCheckBox
@onready var discard_button = $MarginContainer/VBoxContainer/Buttons/Discard

@onready var main_menu: PackedScene = load("res://screens/main_menu.tscn")

func _ready():
	discard_button.text = "BACK"
	show_tutorial.button_pressed = Config.show_tutorial
	
func _process(_delta):
	if Input.is_action_just_pressed("ui_cancel"):
		self._on_discard_pressed()

func _on_discard_pressed():
	get_tree().change_scene_to_packed(main_menu)
	
func _on_save_pressed():
	Config.show_tutorial = show_tutorial.button_pressed
	Config.save()
	get_tree().change_scene_to_packed(main_menu)
	
func update_discard_button():
	var dirty = \
		Config.show_tutorial != show_tutorial.button_pressed
	discard_button.text = "DISCARD" if dirty else "BACK"
