extends Control
@export var icon: Texture2D
# Called when the node enters the scene tree for the first time.
var on_select: Callable



func setup(perk: Perk, select: Callable):
	$Button.modulate.a = 0
	$Card/Name.text = perk.name
	$Card/Description.text = perk.description
	if perk.icon != null:
		$Card/Name/TextureRect.texture = perk.icon
	animate_in()
	$Button.modulate.a = 0.3
	$Button.mouse_entered.connect(func(): $Button.modulate.a = 0.6)
	$Button.mouse_exited.connect(func(): $Button.modulate.a = 0.3)
	on_select = select

	

func _on_button_pressed() -> void:
	await animate_out()
	on_select.call()
	pass # Replace with function body.

func animate_in():
	await get_tree().process_frame
	var start_y = global_position.y + 500
	var end_y = global_position.y
	global_position.y = start_y
	var tween = create_tween()
	tween.tween_property(self, "global_position:y", end_y, 0.3).set_ease(Tween.EASE_OUT).set_trans(Tween.TRANS_QUAD)
	
func animate_out():
	var start_y = global_position.y 
	var end_y = global_position.y - 500
	global_position.y = start_y
	var tween = create_tween()
	tween.tween_property(self, "global_position:y", end_y, 0.3).set_ease(Tween.EASE_IN).set_trans(Tween.TRANS_QUAD)
	await tween.finished
		
