extends DebugMenuBase


func _ready():
	# Set specific configuration for Match3DebugMenu
	log_category = "Match3"
	target_script_path = "res://scenes/game/gameplays/match3_gameplay.gd"

	# Call parent's _ready
	super._ready()

	DebugManager.log_debug("Match3DebugMenu _ready() completed", log_category)

	# Initialize with current debug state if enabled
	var current_debug_state = DebugManager.is_debug_enabled()
	if current_debug_state:
		_on_debug_toggled(true)


func _find_target_scene():
	# Debug menu is now: Match3 -> UILayer -> Match3DebugMenu
	# So we need to go up two levels: get_parent() = UILayer, get_parent().get_parent() = Match3
	var ui_layer = get_parent()
	if ui_layer and ui_layer is CanvasLayer:
		var potential_match3 = ui_layer.get_parent()
		if potential_match3 and potential_match3.get_script():
			var script_path = potential_match3.get_script().resource_path
			if script_path == target_script_path:
				match3_scene = potential_match3
				DebugManager.log_debug(
					(
						"Found match3 scene: "
						+ match3_scene.name
						+ " at path: "
						+ str(match3_scene.get_path())
					),
					log_category
				)
				_update_ui_from_scene()
				_stop_search_timer()
				return

	# If we couldn't find it, clear the reference and continue searching
	match3_scene = null
	DebugManager.log_error("Could not find match3_gameplay scene", log_category)
	_start_search_timer()
