extends Control
class_name Reservation

const Colors = {
	1: Color("00b1a1d6"),
	2: Color("f431e0d6"),
	3: Color("eb7130d6")
}

enum Fonts {
	BIG,
	MEDIUM
}

@onready var _main: Main = get_tree().get_current_scene()
@onready var _title = $Vertical/Horizontal/Section/SectionPanel/SectionLabel
@onready var _panel = $Vertical/Horizontal/Section/SectionPanel
@onready var _indent = $Vertical/Indent

var _hour_size : int
var _minutes : int
var _id : String

func _ready():
	initialize_signals()

func _process(delta):
	_process_hour_size()

func _process_hour_size():
	_hour_size = get_viewport_rect().size.y/15
	_panel.size.y = _minutes * _hour_size / 60
	custom_minimum_size.y = _panel.size.y

func initialize_signals():
	_panel.gui_input.connect(_on_section_panel_gui_input)

func set_title(title):
	_title.text = title

func set_start_time(minutes):
	_indent.set_minutes(minutes)

func set_duration_time(minutes):
	_minutes = minutes

func set_color(color):
	var new_style_box: StyleBoxFlat = _panel.get("theme_override_styles/panel").duplicate()
	new_style_box.bg_color = Colors[int(color)]
	_panel.set("theme_override_styles/panel", new_style_box)

func set_font(font: Fonts):
	match font:
		Fonts.BIG:
			_title.theme = load("res://assets/themes/big.tres")
		Fonts.MEDIUM:
			_title.theme = load("res://assets/themes/medium.tres")

func set_id(id):
	_id = id

func _on_section_panel_gui_input(event):
	if event is InputEventScreenTouch or (event is InputEventMouseButton and event.pressed):
		print("emit open reservation info signal")

		var repo = _main.get_reservation_repo()
		repo.set_selected_reservation_id(_id)

		_main.load_page(Main.Pages.ReservationEdit, true)
