extends Control

class_name SettingsMenu

@onready var audio_options_container: VBoxContainer = $%AudioOptionsContainer
@onready var reset_button: Button = $%ResetToDefault_Button
@onready var close_button: Button = $%Close_Button

func _ready() -> void:
	reset_button.pressed.connect(_on_reset_to_default_button_pressed)
	close_button.pressed.connect(_on_close_button_pressed)
	_refresh_audio_options()

func _get_audio_options() -> Array[AudioOption]:
	var audio_options: Array[AudioOption] = []

	for child in audio_options_container.get_children():
		if child is AudioOption:
			audio_options.append(child)

	return audio_options

func _refresh_audio_options() -> void:
	for audio_option in _get_audio_options():
		audio_option.refresh()

func _apply_current_audio_values() -> void:
	for audio_option in _get_audio_options():
		audio_option.apply_current_value()

func _on_reset_to_default_button_pressed() -> void:
	for audio_option in _get_audio_options():
		audio_option.reset_to_default()

func _on_close_button_pressed() -> void:
	visible = false
