extends Panel

@onready var music_toggle: CheckButton = %MusicToggle
@onready var chop_toggle: CheckButton = %ChopToggle
@onready var money_toggle: CheckButton = %MoneyToggle
@onready var close_button: Button = %CloseButton

func _ready():
	# Initialize toggle states from Global settings
	music_toggle.button_pressed = Global.play_background_music
	chop_toggle.button_pressed = Global.play_chop_sound
	money_toggle.button_pressed = Global.play_money_sound

	# Connect signals
	music_toggle.toggled.connect(_on_music_toggled)
	chop_toggle.toggled.connect(_on_chop_toggled)
	money_toggle.toggled.connect(_on_money_toggled)
	close_button.pressed.connect(_on_close_pressed)

	# Start hidden
	visible = false

func _on_music_toggled(enabled: bool):
	Global.play_background_music = enabled
	var audio_manager = get_node("/root/Audio")
	if enabled:
		audio_manager.play_background_music()
	else:
		audio_manager.stop_background_music()

func _on_chop_toggled(enabled: bool):
	Global.play_chop_sound = enabled

func _on_money_toggled(enabled: bool):
	Global.play_money_sound = enabled

func _on_close_pressed():
	visible = false

func toggle_visibility():
	visible = !visible
