package xyz.thastertyn.ContentDisplay.Content;

import java.io.IOException;
import java.net.UnknownHostException;

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

public class Rozvrh extends JecnaContent {
	
	private Panel rozvrhPanel = new Panel();
	private Label borderLabel = new Label("Rozvrh");
	private xyz.thastertyn.JecnaParse.Rozvrh rozvrh = new xyz.thastertyn.JecnaParse.Rozvrh();

	private boolean hasStarted = false;

	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> t = new Table<>(labels);

	@Override
	public void download()
	{
		try{
			rozvrh.downloadRozvrh();
	
			String[][] rozvrhArray = rozvrh.getRozvrh();
	
			String[] den = new String[11];
	
			for(int i = 0; i < rozvrhArray.length; i++)
			{
				den[0] = daysLabels[i];
				for(int j = 1; j < rozvrhArray[i].length + 1; j++)
				{
					den[j] = (rozvrhArray[i][j - 1].isBlank()) ? " - " : rozvrhArray[i][j - 1];
				}
	
				t.getTableModel().addRow(den);
			}
			rozvrhPanel.addComponent(t);
			hasStarted = true;
		}catch(UnknownHostException e)
		{
			rozvrhPanel.addComponent(new Label("A connection error occurred"));
		}catch(IOException e)
		{
			rozvrhPanel.addComponent(new Label("An error occurred"));
		}
	}

	@Override
	public boolean hasStarted()
	{
		return hasStarted;
	}

	@Override
	public Panel getPanel()
	{
		return rozvrhPanel;
	}

	@Override
	public Label getLabel()
	{
		return borderLabel;
	}

	@Override
	public void specify(int y, int hy) {
		// TODO Auto-generated method stub
		throw new UnsupportedOperationException("Unimplemented method 'specify'");
	}

	@Override
	public void getOptions(WindowBasedTextGUI textGUI) {
		// TODO Auto-generated method stub
		throw new UnsupportedOperationException("Unimplemented method 'getOptions'");
	}
}
