extends VBoxContainer

signal changed
signal leave_stage

var has_stage:bool = false:
	set(stage):
		has_stage = stage
		if is_node_ready() and has_stage:
			%ExpandButton.grab_focus()

@export var is_in_beginning: bool = false
var current_music_decay:float = 0

@onready var expand_button: Button = %ExpandButton
@onready var content_note_box: CheckBox = %ContentNoteButton
@onready var allow_skip_button: CheckBox = %AllowSkipButton

func _ready() -> void:
	if is_in_beginning:
		%SaveButton.text = "save and continue"
	else:
		%SaveButton.text = "save and exit"
	
	update_ui_from_state()

	content_note_box.pressed.connect(func(value): State.show_content_notes = value)
	allow_skip_button.pressed.connect(func(value): State.allow_skipping = value)
	
	%SaveButton.pressed.connect(_on_exit_button_pressed)
	%ExpandButton.pressed.connect(
		func():
			%Reveal.play("reveal")
			%ExpandButton.disabled = true
			)

func update_ui_from_state():
	content_note_box.button_pressed = State.show_content_notes
	allow_skip_button.button_pressed = State.allow_skipping
	
func _on_exit_button_pressed() -> void:
	leave_stage.emit()
	State.save_settings()
	State.leave_stage(self)
