extends Node

@export var view_2d: PackedScene
@export var view_3d: PackedScene

@export var show_view_2d: bool
@export var show_view_3d: bool

var view_2d_child: Node
var view_3d_child: Node

func _ready() -> void:
	if show_view_2d:
		view_2d_child = view_2d.instantiate()
		add_child(view_2d_child)
	if show_view_3d:
		view_3d_child = view_3d.instantiate()
		add_child(view_3d_child)
	
	SettingSignals.settings_closed.connect(_on_settings_closed)
	ServerSignals.sensor_approved.connect(_on_sensor_approced)
	ServerSignals.sensor_declined.connect(_on_sensor_declined)
	ServerSignals.sensor_request_received.connect(_on_sensor_request_received)

func add_widget(widget_type: String, widget_position: Vector2, widget_scale: float):
	pass

func _on_sensor_request_received(sensor_ip, sensor_data):
	print('here')
	_on_open_settings_pressed()
	
func _on_sensor_approced(sensor_ip):
	_on_settings_closed()
	
func _on_sensor_declined(sensor_ip):
	_on_settings_closed()

func _on_open_settings_pressed() -> void:
	if view_2d_child != null:
		remove_child(view_2d_child)
	if view_3d_child != null:
		remove_child(view_3d_child)

func _on_settings_closed():
	if view_2d_child != null:
		add_child(view_2d_child)
	if view_3d_child != null:
		add_child(view_3d_child)
