class_name SectionButton
extends Button

# Used to notify other nodes that the dragging of this node has ended
signal drag_ended

export(Color) var normal_color: Color = Color(0, 0, 0)
export(Color) var pressed_color: Color = Color(0.15, 0.15, 0.15)

func _ready() -> void:
	$ColorRect.set_frame_color(normal_color)
	if .get_text():
		set_text(.get_text())
		.set_text("")


func get_drag_data(_position: Vector2) -> int:
	var ghost = duplicate(0)
	ghost.connect("tree_exiting", self, "_on_drag_preview_tree_exiting")
	set_drag_preview(ghost)
	return get_position_in_parent()


func set_text(text: String) -> void:
	$"Label".set_text(text)


func get_text() -> String:
	return $"Label".get_text()


func set_active(active: bool) -> void:
	if active:
		$ColorRect.set_frame_color(pressed_color)
	else:
		$ColorRect.set_frame_color(normal_color)


func _on_drag_preview_tree_exiting() -> void:
	emit_signal("drag_ended")
