package xyz.thastertyn.UserInterface.Content;

import java.util.ArrayList;
import java.util.List;

import com.googlecode.lanterna.gui2.Label;
import com.googlecode.lanterna.gui2.Panel;
import com.googlecode.lanterna.gui2.table.Table;

import xyz.thastertyn.UserInterface.Listeners.UpdateListener;

public class Timetable extends JecnaContent {

	private xyz.thastertyn.Scrape.Timetable rozvrh = new xyz.thastertyn.Scrape.Timetable();

	private String[] labels = {"Den", "7:30-8:15", "8:25-9:10", "9:20-10:05", "10:20-11:05", "11:15-12:00", "12:10-12:55", "13:05-13:50", "14:00-14:45", "14:55-15:40", "15:50-16:35"};
	//private String[] labels = {"Den", "1.", "2.", "3.", "4.", "5.", "6.", "7.", "8.", "9.", "10."};

	String[] daysLabels = {"PO", "UT", "ST", "CT", "PA"};
	
	Table<String> table;

	public Timetable(UpdateListener listener)
	{
		super(listener);
		this.mainPanel = new Panel();
		this.borderLabel = new Label("Rozvrh");
		super.scraper = this.rozvrh;
	}

	@Override
	protected void setGUI()
	{
		mainPanel.removeAllComponents();
		table = new Table<>(labels);
		xyz.thastertyn.Types.Timetable timetable = rozvrh.getRozvrh();
	
		for(int day = 0; day < 5; day++)
		{
			List<String> currentRow = new ArrayList<>();

			// Set the day (Po, Ut, St,...)
			currentRow.add(daysLabels[day]);

			// Add the classes
			for(int hour = 0; hour < 10; hour++)
			{
				currentRow.add((timetable.get(day).get(hour).isBlank()) ?
					" - " // Empty class, nothing taught at that moment
					:
					timetable.get(day).get(hour)); // Get class
			}

			table.getTableModel().addRow(currentRow);
		}
		mainPanel.addComponent(table);
	}
}
