class_name SaveGameDisplay extends Button

func _init(save: SaveGame, id: int) -> void:
	var base_container:= HBoxContainer.new()
	base_container.alignment = BoxContainer.ALIGNMENT_CENTER
	add_child(base_container)
	
	var texture:= TextureRect.new()
	texture.texture = save.thumbnail
	texture.size_flags_vertical = Control.SIZE_SHRINK_CENTER
	
	base_container.add_child(texture)
	var heading_split:= HSplitContainer.new()
	var heading:= Label.new()
	
	heading.text = "Slot %d" % id
	heading.theme_type_variation = "HeaderLarge"
	
	var localised_date_time: String
	var localised_weekday: PackedStringArray
	var date_time: Dictionary = Time.get_datetime_dict_from_unix_time(save.last_saved)
	
	match TranslationServer.get_locale():
		"de":
			localised_weekday = ["Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag", "Sonntag"]
			localised_date_time = "%s, %d.%d.%d um %d:%02d" % [localised_weekday[date_time["weekday"]],
															date_time["day"],
															date_time["month"],
															date_time["year"],
															date_time["hour"],
															date_time["minute"]
															]
		_:
			localised_weekday = ["Monday", "Tuseday", "Wensday", "Thursday", "Friday", "Saturday", "Sunday"]
			localised_date_time = "%s, %d/%d/%d - %d:%02d (%s)" % [localised_weekday[date_time["weekday"]],
																date_time["day"],
																date_time["month"],
																date_time["year"],
																date_time["hour"] % 12 if date_time["hour"] % 12 > 1 else 12 if date_time["hour"] == 12 or date_time["minute"] == 0 else 0,
																date_time["minute"],
																"AM" if date_time["hour"] < 12 else "PM"]
	
	var time:= Label.new()
	time.text = localised_date_time if not save.current_room == 0 else "Start new game."
	
	var info:= VBoxContainer.new()
	base_container.add_child(info)
	
	info.add_child(heading_split)
	heading_split.add_child(heading)
	heading_split.add_child(time)
	
	var room:= Label.new()
	room.theme_type_variation = "HeaderMedium"
	match save.current_room:
		State.rooms.MENU:
			room.text = "Empty Slot"
		State.rooms.DRAVEN:
			room.text = "Intro Sequence"
		State.rooms.YOUTH:
			room.text = "Inside youth room."
		State.rooms.TRANSITION:
			room.text = "Transitioning to Adulthood."
		State.rooms.ADULTHOOD:
			room.text = "Exploring Adulthood."	
		State.rooms.ENDING:
			room.text = "Ending"
	
	var state: = Label.new()
	state.text = ("""
	Mementos collected: 1/4
	Connections found: 1/8
	Secrets found: 1/4
	""").strip_edges()
	
	info.add_child(room)
	info.add_child(state)
	info.size_flags_vertical = Control.SIZE_SHRINK_CENTER
	
	custom_minimum_size = base_container.get_combined_minimum_size() + Vector2(64, 32)

	theme_type_variation = "SaveButton"
