package de.heatup.ui.menu;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JLabel;
import javax.swing.JPanel;

import de.heatup.logging.Logger;
import de.heatup.ui.FontLoader;
import de.heatup.ui.PanelBuilder;

public class CreditsPanel {
	
	private static JPanel credits = new JPanel();
	private static GridLayout grid = new GridLayout(9, 1);
	
	// font settings
	private static FontLoader fl = new FontLoader();
	private static Font emulogic;
	private static Font emulogicHeadline;
	private static Font emulogicDivider;
	private static Font emulogicSmall;
	private static Font ttfbase;
	
	// panels and labels
	private static JPanel headline, divider, divider2, name1, name2, name3, name4, name5, exit;
	private static JLabel headlineLabel, dividerLabel, dividerLabel2, name1Label, name2Label, name3Label, name4Label, name5Label, exitLabel;
	
	public CreditsPanel() { }
	
	public static void setCreditsPanel() {
		
		credits.setBackground(Color.BLACK);
		credits.setLayout(grid);
		
		ttfbase = FontLoader.getFont();
		emulogicHeadline = ttfbase.deriveFont(Font.PLAIN, 28);
		emulogic = ttfbase.deriveFont(Font.PLAIN, 12);
		emulogicDivider = ttfbase.deriveFont(Font.PLAIN, 20);
		emulogicSmall = ttfbase.deriveFont(Font.PLAIN, 10);
		
		createCredits();
	}
	 
	private static void createCredits() {
		
		headline = new JPanel();
		headline.setBackground(Color.BLACK);
		
		headlineLabel = new JLabel("HeatUp - Credits");
		headlineLabel.setForeground(Color.YELLOW);
		headlineLabel.setFont(emulogicHeadline);
		headline.add(headlineLabel);
		
		divider = new JPanel();
		divider.setBackground(Color.BLACK);
		
		dividerLabel = new JLabel("-----------------------------------");
		dividerLabel.setForeground(Color.YELLOW);
		dividerLabel.setFont(emulogicDivider);
		divider.add(dividerLabel);
		
		divider2 = new JPanel();
		divider2.setBackground(Color.BLACK);
		
		dividerLabel2 = new JLabel("-----------------------------------");
		dividerLabel2.setForeground(Color.YELLOW);
		dividerLabel2.setFont(emulogicDivider);
		divider2.add(dividerLabel2);
		
		name1 = new JPanel();
		name1.setBackground(Color.BLACK);
		
		name1Label = new JLabel("Daniel Aberger - daniel.aberger@stud.hs-hannover.de");
		name1Label.setForeground(Color.YELLOW);
		name1Label.setFont(emulogic);
		name1.add(name1Label);

		name2 = new JPanel();
		name2.setBackground(Color.BLACK);
		
		name2Label = new JLabel("Andreas Hainke - andreas.hainke@stud.hs-hannover.de");
		name2Label.setForeground(Color.YELLOW);
		name2Label.setFont(emulogic);
		name2.add(name2Label);
		
		name3 = new JPanel();
		name3.setBackground(Color.BLACK);
		
		name3Label = new JLabel("Ivan Parsikov - ivan.parsikov@stud.hs-hannover.de");
		name3Label.setForeground(Color.YELLOW);
		name3Label.setFont(emulogic);
		name3.add(name3Label);
		
		name4 = new JPanel();
		name4.setBackground(Color.BLACK);
		
		name4Label = new JLabel("Felix Kleinschmidt - felix.kleinschmidt@stud.hs-hannover.de");
		name4Label.setForeground(Color.YELLOW);
		name4Label.setFont(emulogic);
		name4.add(name4Label);
		
		name5 = new JPanel();
		name5.setBackground(Color.BLACK);
		
		name5Label = new JLabel("Tim Carlsson - tim-nils.carlsson@stud.hs-hannover.de");
		name5Label.setForeground(Color.YELLOW);
		name5Label.setFont(emulogic);
		name5.add(name5Label);
		
		exit = new JPanel();
		exit.setBackground(Color.BLACK);
		
		exitLabel = new JLabel("[ zurück zum Menü ]");
		exitLabel.setForeground(Color.YELLOW);
		exitLabel.setFont(emulogicSmall);
		
		exitLabel.addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent e) {
				// @TODO: implement show credits				
				CreditsPanel.getCreditsPanel().setVisible(false);
				
				PanelBuilder.getOuterPanel().add(MenuPanel.getMenuPanel(), BorderLayout.CENTER);
				MenuPanel.getMenuPanel().setVisible(true);
				
				Logger.write("back to menu");				
			}
		});
		
		exit.add(exitLabel);
		
		
		credits.add(headline);
		credits.add(divider);
		credits.add(name1);
		credits.add(name2);
		credits.add(name3);
		credits.add(name4);
		credits.add(name5);
		credits.add(divider2);		
		credits.add(exit);
	}
	
	public static JPanel getCreditsPanel() {
		credits.setVisible(true);
		return credits;
	}
}
