extends ConfirmationDialog

class_name Interactible

@export var instant: bool = false

var current_draggable: DraggableObject
var current_interaction: Interactible

signal begin_interaction(with: DraggableObject)
signal interacted(with: DraggableObject)

func _ready() -> void:
	if not instant:
		confirmed.connect(interact)
		canceled.connect(cancel_interaction)

func try_interact(draggable: DraggableObject) -> bool:
	if draggable.interactible != null and visible == false:
		current_draggable = draggable
		begin_interaction.emit(current_draggable)
		if instant:
			interact()
		else:
			popup_centered()
		return true
	return false

func interact():
	interacted.emit(current_draggable)
	cleanup()

func cancel_interaction():
	cleanup()

func cleanup():
	current_draggable = null
	current_interaction = null
