@tool
extends Label
## A prompt with the input symbol bound to the given action.

const PROMPT_FORMAT := "{0} - {1}"

const UNKNOWN_LABEL_SYM := "[unknown]"

@export var action: StringName:
	set(value):
		action = value
		_update()

@export var label: String:
	set(value):
		label = value
		_update()


func _ready() -> void:
	_update()


func _update() -> void:
	var input_symbol: String
	var actions := InputMap.action_get_events(action)
	if actions:
		var primary := actions[0]
		input_symbol = PromptMap.from_event(primary)

	text = PROMPT_FORMAT.format(
		[
			input_symbol if input_symbol else PromptMap.UNKNOWN_INPUT_SYMBOL,
			label if label else UNKNOWN_LABEL_SYM
		]
	)
