package de.heatup.ui.menu;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
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.Main;
import de.heatup.ui.PanelBuilder;

public class MapChooseHighschorePanel {

	private static JPanel mapChooseHighscorePanel = new JPanel();
	
	// Panels and Labels for mapChooseHighschorePanek	
	private static JPanel headingPanel, dividerPanel, map1Panel, map2Panel, map3Panel, map4Panel;
	private static JLabel headingLabel, dividerLabel, map1Label, map2Label, map3Label, map4Label;
	
	// Font loader and font Settings
	private static FontLoader fl = new FontLoader();
	private static Font ttfbase, emulogicHeading, emulogicDivider, emulogicSmall;
	
	// PanelGrid
	private static GridLayout grid = new GridLayout(6, 1);
	
	public MapChooseHighschorePanel() {		
		mapChooseHighscorePanel.setSize(new Dimension(800, 600));
		mapChooseHighscorePanel.setBackground(Color.BLACK);
		mapChooseHighscorePanel.setFocusable(false);
		mapChooseHighscorePanel.setVisible(true);
		mapChooseHighscorePanel.setLayout(grid);
		
		// build related fonts
		ttfbase = FontLoader.getFont();
		emulogicHeading = ttfbase.deriveFont(Font.PLAIN, 30);
		emulogicDivider = ttfbase.deriveFont(Font.PLAIN, 20);
		emulogicSmall = ttfbase.deriveFont(Font.PLAIN, 18);
		
		initMapChooseHeading();
		mapChooseHighscorePanel.add(headingPanel);
		mapChooseHighscorePanel.add(dividerPanel);
		
		initMapChooseHighscorePanel();
		mapChooseHighscorePanel.add(map1Panel);
		mapChooseHighscorePanel.add(map2Panel);
		mapChooseHighscorePanel.add(map3Panel);
		mapChooseHighscorePanel.add(map4Panel);
	}
	
	private static void initMapChooseHeading() {
		headingPanel = new JPanel();
		headingPanel.setSize(new Dimension(800, 50));
		headingPanel.setBackground(Color.BLACK);
		headingPanel.setFocusable(false);
		headingPanel.setVisible(true);
		
		headingLabel = new JLabel();
		headingLabel.setForeground(Color.YELLOW);
		headingLabel.setBackground(Color.BLACK);
		headingLabel.setVisible(true);
		headingLabel.setFont(emulogicHeading);
		headingLabel.setText("HeatUp - Highscores");
		
		headingPanel.add(headingLabel);
		
		dividerPanel = new JPanel();
		dividerPanel.setSize(new Dimension(800, 50));
		dividerPanel.setBackground(Color.BLACK);
		dividerPanel.setFocusable(false);
		dividerPanel.setVisible(true);
		
		dividerLabel = new JLabel();
		dividerLabel.setForeground(Color.YELLOW);
		dividerLabel.setBackground(Color.BLACK);
		dividerLabel.setVisible(true);
		dividerLabel.setFont(emulogicDivider);
		dividerLabel.setText("-------------------------------");
		
		dividerPanel.add(dividerLabel);
	}
	
	private static void initMapChooseHighscorePanel() {
		map1Panel = new JPanel();
		map1Panel.setSize(new Dimension(800, 20));
		map1Panel.setVisible(true);
		map1Panel.setBackground(Color.BLACK);
		
		map1Label = new JLabel();
		map1Label.setBackground(Color.BLACK);
		map1Label.setForeground(Color.YELLOW);
		map1Label.setFont(emulogicSmall);
		map1Label.setText("Map -1-");
		map1Label.addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent e) {

				MapChooseHighschorePanel.getMapChooseHighscorePanel().setVisible(false);
				HighscorePanel p = new HighscorePanel(1);
				//HighscorePanel.setMapID(1);
				PanelBuilder.getOuterPanel().add(HighscorePanel.getHighscorePanel(), BorderLayout.CENTER);
				
				/**
				if(MenuPanel.gameExists == 1) {

					
				} else if(MenuPanel.gameExists == 2) {
					if(Main.getPause()) {
						
					}
				}
				*/
				Logger.write("Show Highscore for : " + map1Label.getText());
			}
		});
		map1Panel.add(map1Label);
		
		//
		
		map2Panel = new JPanel();
		map2Panel.setSize(new Dimension(800, 20));
		map2Panel.setVisible(true);
		map2Panel.setBackground(Color.BLACK);
		
		map2Label = new JLabel();
		map2Label.setBackground(Color.BLACK);
		map2Label.setForeground(Color.YELLOW);
		map2Label.setFont(emulogicSmall);
		map2Label.setText("Map -2-");
		map2Label.addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent e) {

				MapChooseHighschorePanel.getMapChooseHighscorePanel().setVisible(false);				
				HighscorePanel p = new HighscorePanel(2);
				//HighscorePanel.setMapID(2);
				PanelBuilder.getOuterPanel().add(HighscorePanel.getHighscorePanel(), BorderLayout.CENTER);
				
				/**
				if(MenuPanel.gameExists == 1) {

					
				} else if(MenuPanel.gameExists == 2) {
					if(Main.getPause()) {
						
					}
				}
				*/
				Logger.write("Show Highscore for : " + map2Label.getText());
			}
		});
		map2Panel.add(map2Label);
		
		//
		
		map3Panel = new JPanel();
		map3Panel.setSize(new Dimension(800, 20));
		map3Panel.setVisible(true);
		map3Panel.setBackground(Color.BLACK);
		
		map3Label = new JLabel();
		map3Label.setBackground(Color.BLACK);
		map3Label.setForeground(Color.YELLOW);
		map3Label.setFont(emulogicSmall);
		map3Label.setText("Map -3-");
		map3Label.addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent e) {

				MapChooseHighschorePanel.getMapChooseHighscorePanel().setVisible(false);
				HighscorePanel p = new HighscorePanel(3);
				//HighscorePanel.setMapID(3);
				PanelBuilder.getOuterPanel().add(HighscorePanel.getHighscorePanel(), BorderLayout.CENTER);

				/**
				if(MenuPanel.gameExists == 1) {

					
				} else if(MenuPanel.gameExists == 2) {
					if(Main.getPause()) {
						
					}
				}
				*/
				Logger.write("Show Highscore for : " + map3Label.getText());
			}
		});
		map3Panel.add(map3Label);
		
		//
		
		map4Panel = new JPanel();
		map4Panel.setSize(new Dimension(800, 20));
		map4Panel.setVisible(true);
		map4Panel.setBackground(Color.BLACK);
		
		map4Label = new JLabel();
		map4Label.setBackground(Color.BLACK);
		map4Label.setForeground(Color.YELLOW);
		map4Label.setFont(emulogicSmall);
		map4Label.setText("Map -Custom-");
		map4Label.addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent e) {
				
				MapChooseHighschorePanel.getMapChooseHighscorePanel().setVisible(false);
				HighscorePanel p = new HighscorePanel(0);
				//HighscorePanel.setMapID(0);
				PanelBuilder.getOuterPanel().add(HighscorePanel.getHighscorePanel(), BorderLayout.CENTER);
				
				/**
				if(MenuPanel.gameExists == 1) {

					
				} else if(MenuPanel.gameExists == 2) {
					if(Main.getPause()) {
						
					}
				}
				*/
				Logger.write("Show Highscore for : " + map4Label.getText());
			}
		});
		map4Panel.add(map4Label);
		
	}
	
	public static JPanel getMapChooseHighscorePanel() {
		return mapChooseHighscorePanel;
	}
}
