extends Control

signal chat_message_sent(text)

onready var log_text = $ResizablePanel/RichTextLabel
onready var chat_bar = $ResizablePanel/LineEdit

func _input(event: InputEvent) -> void:
	if event is InputEventMouseButton:
		if not chat_bar_focus:
			chat_bar.release_focus()
	if event.is_action_released("ui_chat") and chat_bar_focus == false:
		chat_bar.grab_focus()

func add_line(line: String) -> void:
	log_text.append_bbcode(line)

var chat_bar_focus = false

func _chat_bar_status(editing: bool) -> void:
	$"/root/scene".writing = editing

func _chat_bar_focus(entered: bool) -> void:
	chat_bar_focus = entered

func _text_submitted(text):
	emit_signal("chat_message_sent", text)
	chat_bar.text = ""
	chat_bar.release_focus()
