extends Control

@onready var shift_cycle_template = preload("res://templates/shift_cycle.tscn")
@onready var cycle_list : ReorderableVBox = %CycleList
@onready var delete_bin : PanelContainer = %DeleteBin
var delete_tween : Tween

func _ready() -> void:
	delete_tween = delete_bin.create_tween()
	delete_tween.tween_property(delete_bin, "self_modulate", Color.WHITE, .3)
	delete_tween.tween_property(delete_bin, "self_modulate", Color.DIM_GRAY, .3)
	delete_tween.set_loops(-1)
	delete_tween.pause()
	delete_bin.self_modulate = Color.DIM_GRAY

func _on_drag_stopped(cycle : ShiftCycle):
	cycle.drop()
	if(delete_bin.get_global_rect().has_point(get_global_mouse_position())
	and len(cycle_list.get_children()) > 1):
		delete_tween.pause()
		delete_bin.self_modulate = Color.DIM_GRAY
		cycle.queue_free()

func _on_drag_started(cycle : ShiftCycle):
	cycle.lift()
	pass

func _on_add_shift_button_pressed() -> void:
	var cycle = shift_cycle_template.instantiate()
	cycle_list.add_child(cycle)


func _on_accept_button_pressed() -> void:
	var schedule = []
	for child : ShiftCycle in cycle_list:
		schedule.append([child.work_shift, child.open_shift])
	Guild.shift_schedule = schedule
	Game.switch_dialogue("game_start", "")
	pass # Replace with function body.
