extends Panel


@onready var booking_screen = $"%BookingScreen"
@onready var lesson_grid = $"%LessonGrid"
@onready var settings_button = $"%SettingsButton"
@onready var important_vars = $"%impvars"
@onready var booking_vars = $"%bookings"
@onready var timer = $"%time"
@onready var err_label = $"%ErrLabel"
@onready var clear_button = $"%ClearButton"
@onready var name1 = $"%Name1"
@onready var name2 = $"%Name2"
@onready var form1 = $"%Form1"
@onready var form2 = $"%Form2"
@onready var name3 = $"%Name3"
@onready var form3 = $"%Form3"
@onready var name4 = $"%Name4"
@onready var form4 = $"%Form4"
@onready var reason = $"%ReasonField"


func _clear_form():
	name1.text = ""
	name2.text = ""
	form1.text = ""
	form2.text = ""
	name3.text = ""
	name4.text = ""
	form3.text = ""
	form4.text = ""
	reason.text = ""


func restore_names_to_four():
	name3.visible = true
	form3.visible = true
	name4.visible = true
	form4.visible = true


func _on_CancelButton_pressed():
	booking_screen.visible = false
	lesson_grid.visible = true
	settings_button.visible = true
	err_label.visible = false
	clear_button.visible = false
	restore_names_to_four()
	_clear_form()


func _book_it():
	booking_vars.set_values()
	_clear_form()


func _on_BookButton_pressed():
	if name1.text == "" or reason.text =="":
		err_label.visible = true
	else:
		var namer = "/root/MainStartScreen/ButtonGrid/" + important_vars.pod + "L" + str(important_vars.time)
		var sp = get_node(str(namer))
		sp.text = "BOOKED"

		_book_it()
		_on_CancelButton_pressed()


func _on_ClearButton_pressed():
	var namer = "/root/MainStartScreen/ButtonGrid/" + important_vars.pod + "L" + str(important_vars.time)
	var sp = get_node(str(namer))
	sp.text = ""
	_clear_form()
	_book_it()
	_on_CancelButton_pressed()
