package gui.panels.agenda;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.Calendar;
import java.util.GregorianCalendar;

import javax.swing.JPanel;
import javax.swing.JScrollPane;
import agenda.Agenda;

@SuppressWarnings("serial")
public class AgendaPane extends JPanel {
	private GregorianCalendar currentdate;
	private	DaySelectorPane dayselector;
	private InfoPane infopanel;
	private final AgendaScrollPane agendapanel;
	private String actName;
	private String actInfo;
	
	public AgendaPane(Agenda agenda){
		this.actName = "Act";
		this.actInfo = "Act info";
		this.setOpaque(true);
		setLayout(new BorderLayout());
		
		infopanel = new InfoPane(actName, actInfo);

		agendapanel = new AgendaScrollPane(agenda, infopanel);
		dayselector = new DaySelectorPane();
		
		JScrollPane scroll = new JScrollPane(agendapanel);
		scroll.getVerticalScrollBar().setUnitIncrement(20);
		
		this.add(scroll, BorderLayout.CENTER);
		this.add(dayselector, BorderLayout.SOUTH);
		this.add(infopanel, BorderLayout.WEST);
		
		if(agenda.getActs().size()==0){
			setCurrentdate(new GregorianCalendar());
		}else{
			GregorianCalendar date = agenda.getActs().get(0).getActTime().getBeginTime();
			setCurrentdate(new GregorianCalendar(date.get(Calendar.YEAR), date.get(Calendar.MONTH), date.get(Calendar.DAY_OF_MONTH)));
		}


		dayselector.getButtonLeft().addMouseListener(new MouseListener() {
			@Override
			public void mouseClicked(MouseEvent e) {
				currentdate.add(Calendar.DAY_OF_MONTH, -1);
				setCurrentdate(currentdate);
						}
			@Override
			public void mouseEntered(MouseEvent arg0) {
				
			}
			@Override
			public void mouseExited(MouseEvent arg0) {
				
			}
			@Override
			public void mousePressed(MouseEvent arg0) {
				
			}

			@Override
			public void mouseReleased(MouseEvent arg0) {

			}
		});
		dayselector.getButtonRight().addMouseListener(new MouseListener() {
			@Override
			public void mouseClicked(MouseEvent e) {
				currentdate.add(Calendar.DAY_OF_MONTH, 1);
				setCurrentdate(currentdate);
			}
			@Override
			public void mouseEntered(MouseEvent arg0) {
				
			}
			@Override
			public void mouseExited(MouseEvent arg0) {
				
			}
			@Override
			public void mousePressed(MouseEvent arg0) {
				
			}

			@Override
			public void mouseReleased(MouseEvent arg0) {

			}
		});
	}
	public void setCurrentdate(GregorianCalendar date){
		this.currentdate = date;
		dayselector.setDate(date);
		agendapanel.setDate(currentdate);
	}
	
	public void setActName(String name){
		this.actName = name;
	}
	
	public void setActInfo(String info){
		this.actInfo = info;
	}
	
	
}
