extends Node3D

@onready var tooltip: Label3D = $Tooltip
@onready var mesh_node: MeshInstance3D = $SphereMesh

func _ready() -> void:
	add_to_group("interactable")
	tooltip.visible = false
	var tw := create_tween().set_loops()
	tw.tween_property(self, "position:y", 0.7, 0.9)
	tw.tween_property(self, "position:y", 0.3, 0.9)

func _process(delta: float) -> void:
	rotation.y += delta * 1.8
	mesh_node.rotation.x += delta * 0.9
	var players := get_tree().get_nodes_in_group("player")
	if players.is_empty():
		tooltip.visible = false
		return
	var p := players[0] as Node3D
	tooltip.visible = p != null and global_position.distance_to(p.global_position) < 2.5

func interact(player: Node) -> void:
	player.call("apply_upgrade_enchant")
	queue_free()
