package xyz.thastertyn.ContentDisplay.Content;

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

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

import xyz.thastertyn.Tuples.Pair;

public class OmluvnyList extends JecnaContent{
	
	private Panel omluvnyPanel = new Panel();
	private Label borderLabel = new Label("Omluvny L.");
	private xyz.thastertyn.JecnaParse.OmluvnyList omluvnyList = new xyz.thastertyn.JecnaParse.OmluvnyList();

	private boolean hasStarted = false;

	@Override
	public void download() {
		try{
			omluvnyList.downloadOmluvnyList();

			ArrayList<Pair<String, String>> a = omluvnyList.getData();

			for(Pair<String, String> p : a)
			{
				omluvnyPanel.addComponent(new Label(p.getValue0() + " - " + p.getValue1()));
			}
		}catch(UnknownHostException e)
		{
			omluvnyPanel.addComponent(new Label("A connection error occurred"));
		}catch(IOException e)
		{
			omluvnyPanel.addComponent(new Label("An error occurred"));
		}
	}

	@Override
	public Panel getPanel() {
		return omluvnyPanel;
	}
	
	@Override
	public boolean hasStarted() {
		return hasStarted;
	}

	@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'");
	}
}
