class_name SettingsItem
extends Label

@export var parameters: Array[String] = []
@export var current_select: int = 0
@export_group("Selector")
@export var left_cursor: String = "◀"
@export var right_cursor: String = "▶"
@export var left_limit: String = "◁"
@export var right_limit: String = "▷"


func _center_text(string: String, length: int) -> String:
	if string.length() > length:
		return string.left(length)
	var padding: int = length - string.length()
	var left := int(padding / 2.0)
	var right: int = padding - left
	return ' '.repeat(left) + string + ' '.repeat(right)


func decrease_option() -> bool:
	if current_select > 0:
		current_select -= 1
		set_selected_text()
		return true
	return false


func encrease_option() -> bool:
	if current_select < parameters.size() - 1:
		current_select += 1
		set_selected_text()
		return true
	return false


func set_selected_text() -> void:
	var label_text: String = left_limit if current_select <= 0 else left_cursor
	label_text += _center_text(parameters[current_select], 8)
	label_text += right_limit if current_select >= parameters.size() - 1 else right_cursor
	text = label_text


func set_unselected_text() -> void:
	text = ' ' + _center_text(parameters[current_select], 8) + ' '
