extends Area2D
class_name Interactible

# @export_file("*.tscn") var scene_to_trigger: String
@export var message: String
@export var interact_text: String
@export var event: String

signal event_triggered(event_id: String)
signal event_confirmed(event_id: String)

@onready var rich_text_label: RichTextLabel = $RichTextLabel
@onready var confirm_panel: Panel = %ConfirmPanel
@onready var message_box: Label = %MessageBox
@onready var interact_box: RichTextLabel = $RichTextLabel

@export var is_item = false
@onready var confirm_button: Button = %ConfirmButton
@onready var cancel_button: Button = %CancelButton
@onready var ok_button: Button = %OkButton


func activate() -> void:
	visible = true
	monitorable = true
	monitoring = true
	

func deactivate() -> void:
	visible = false
	monitorable = false
	monitoring = false


# Called when the node enters the scene tree for the first time.
func _ready() -> void:
	rich_text_label.visible = false
	confirm_panel.visible = false
	message_box.text = message.to_upper()
	
	if not interact_text.is_empty():
		interact_box.text = interact_text.to_upper()
	
	if is_item:
		confirm_button.visible = false
		cancel_button.visible = false
		ok_button.visible = true

func _on_body_entered(body: Node2D) -> void:
	rich_text_label.visible = true

func _on_body_exited(body: Node2D) -> void:
	rich_text_label.visible = false
	confirm_panel.visible = false
	
func show_confirm():
	confirm_panel.visible = true
	event_triggered.emit(event)

func _on_confirm_button_pressed() -> void:
	confirm_panel.visible = false
	event_confirmed.emit(event)

func _on_cancel_button_pressed() -> void:
	confirm_panel.visible = false
