extends Control

@export var show_animation_time: float = 0.25
@export var text: String = ""

var tween: Tween
@onready var default_left_anchor: float = anchor_left
@onready var default_right_anchor: float = anchor_right

func _ready() -> void:
	mouse_entered.connect(show_menu)
	mouse_exited.connect(hide_menu)
	$Label.text = text

func show_menu() -> void:
	if tween:
		tween.kill()
	
	tween = create_tween()
	tween.tween_property(self,"anchor_right",default_right_anchor + abs(default_left_anchor),show_animation_time)
	tween.parallel()
	tween.tween_property(self,"anchor_left",default_right_anchor,show_animation_time)

func hide_menu() -> void:
	if tween:
		tween.kill()
	
	tween = create_tween()
	tween.tween_property(self,"anchor_right",default_right_anchor,show_animation_time)
	tween.parallel()
	tween.tween_property(self,"anchor_left",default_left_anchor,show_animation_time)

func add_element(node: Node):
	$ScrollContainer/VBoxContainer.add_child(node)
