package de.jaujau.gui;


import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import javax.swing.JLabel;
import javax.swing.ImageIcon;
import javax.swing.SwingConstants;
import de.jaujau.daten.Spielerverwaltung;
import de.jaujau.daten.Texturenpakete;
import de.jaujau.spiellogik.Spiel;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.BoxLayout;
import java.awt.Font;
import java.awt.Toolkit;



/**
 * Klasse GUI
 * @author Elmar Kresse
 * Diese Klasse gibt das JFrame und die Navigation und kann darüber die einzelnen Dashboard Tabs aufrufen und die Texturenauswahl und Hilfe anzeigen.
 */
public class GUI extends JFrame{

  //
  // Variablen
  //
	private static final long serialVersionUID = 1L;
	private boolean menuehidden = false;
	Hilfe_GUI frame = new Hilfe_GUI();
	private Spiel aktuellesSpiel;
  
  //
  // Konstruktor
  //
  public GUI (Texturenpakete texturenpakete, Spielerverwaltung speicherung) {
  	setIconImage(Toolkit.getDefaultToolkit().getImage(GUI.class.getResource("/img/jaujau.png")));
  	setMinimumSize(new Dimension(1000, 600));
	  
  		//JFrame Variablen
	  	setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  		setTitle("JauJau");
  		setPreferredSize(new Dimension(800, 500));
  		setSize(1565, 916);
		getContentPane().setLayout(new BorderLayout(0, 0));

		
		JPanel Menue = new JPanel();
		Menue.setPreferredSize(new Dimension(270, 450));
		getContentPane().add(Menue, BorderLayout.WEST);
		Menue.setLayout(new BoxLayout(Menue, BoxLayout.X_AXIS));
		
		JPanel MenueIcon = new JPanel();
		MenueIcon.setPreferredSize(new Dimension(50, 450));
		MenueIcon.setBackground(new Color(15, 19, 52));
		Menue.add(MenueIcon);
		MenueIcon.setLayout(null);
		
		JPanel help = new JPanel();
		help.setBounds(0, 0, 50, 50);
		help.setBackground(new Color(15, 19, 52));
		MenueIcon.add(help);
		
		JLabel helplable = new JLabel("");
		helplable.setHorizontalTextPosition(SwingConstants.CENTER);
		helplable.setHorizontalAlignment(SwingConstants.CENTER);
		helplable.setIcon(new ImageIcon(GUI.class.getResource("/img/help.png")));
		help.add(helplable);
		
		JPanel menuebtn = new JPanel();
		menuebtn.setBounds(0, 50, 50, 50);
		MenueIcon.add(menuebtn);
		menuebtn.setLayout(new BorderLayout(0, 0));
		
		JLabel menuelabel = new JLabel("");
		menuelabel.setHorizontalTextPosition(SwingConstants.CENTER);
		menuelabel.setHorizontalAlignment(SwingConstants.CENTER);
		menuelabel.setIcon(new ImageIcon(GUI.class.getResource("/img/menue.png")));
		menuebtn.add(menuelabel);
		menuebtn.setBackground(new Color(15, 19, 52));
		
		JPanel menuhide = new JPanel();
		menuhide.setPreferredSize(new Dimension(220, 200));
		menuhide.setBackground(new Color(25, 29, 74));
		Menue.add(menuhide);
		menuhide.setLayout(null);
		
		JLabel startlabel = new JLabel("Startseite");

		startlabel.setBounds(0, 11, 220, 29);
		startlabel.setVerticalAlignment(SwingConstants.TOP);
		startlabel.setForeground(Color.WHITE);
		startlabel.setFont(new Font("Tahoma", Font.PLAIN, 24));
		startlabel.setHorizontalAlignment(SwingConstants.CENTER);
		menuhide.add(startlabel);
		
		JLabel highscorelabel = new JLabel("Highscore");

		highscorelabel.setBounds(0, 51, 220, 29);
		highscorelabel.setHorizontalAlignment(SwingConstants.CENTER);
		highscorelabel.setForeground(Color.WHITE);
		highscorelabel.setFont(new Font("Tahoma", Font.PLAIN, 24));
		menuhide.add(highscorelabel);
		
		JLabel gamelabel = new JLabel("Spielen");

		gamelabel.setHorizontalAlignment(SwingConstants.CENTER);
		gamelabel.setForeground(Color.WHITE);
		gamelabel.setFont(new Font("Tahoma", Font.PLAIN, 24));
		gamelabel.setBounds(0, 91, 220, 29);
		menuhide.add(gamelabel);
		
		
		//Texturen Label
		JLabel texturenlabel = new JLabel("Texturen");
		texturenlabel.setHorizontalAlignment(SwingConstants.CENTER);
		texturenlabel.setForeground(Color.WHITE);
		texturenlabel.setFont(new Font("Tahoma", Font.PLAIN, 24));
		texturenlabel.setBounds(0, 131, 220, 29);
		menuhide.add(texturenlabel);
		
		//Dashboard hinzufügen
		JPanel dashboard = new JPanel();
		dashboard.setBackground(new Color(73, 128, 242));
		getContentPane().add(dashboard, BorderLayout.CENTER);
		dashboard.setLayout(new BorderLayout(0, 0));
		Dashboard_GUI Dashboard_GUI = new Dashboard_GUI(aktuellesSpiel, texturenpakete, speicherung);
		dashboard.add(Dashboard_GUI, BorderLayout.CENTER);
		
		//Event Listener für die Buttons / Label	
		
		
		//Sidemenue Anzeigen Einklappen
		menuebtn.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				if(menuehidden == true) {
					menuhide.setVisible(false);
					Menue.setPreferredSize(new Dimension(50, Menue.getHeight()));
					menuehidden = false;
				}else{
					menuhide.setVisible(true);
					Menue.setPreferredSize(new Dimension(270, Menue.getHeight()));
					menuehidden = true;
				}
				
			}
		});

		//Hilfe anzeigen/ausblenden
		help.addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent e) {
				if(frame.isShowing() == true) {
					frame.setVisible(false);
				}else{
					frame.setVisible(true);
				}
				
			}
		});
		
		//Spiel starten -- Label zum starten des Spiels
		gamelabel.addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent e) {
				aktuellesSpiel = new Spiel(Dashboard_GUI);
				System.out.println("GUI: Spiel GUI geöffnet");
				Dashboard_GUI.showgame(aktuellesSpiel);
			}
		});
		
		
		highscorelabel.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				System.out.println("GUI: Highscore geöffnet");
				Dashboard_GUI.showhighscore();
			}
		});
		
		
		
		startlabel.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				System.out.println("GUI: Start geöffnet");
				Dashboard_GUI.showstart();
			}
		});
		
		
		
		texturenlabel.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				texturenauswaehlen_GUI texturenauswahl = new texturenauswaehlen_GUI(texturenpakete, speicherung);
				System.out.println("GUI: Start geöffnet");
				texturenauswahl.setVisible(true);
			}
		});
		
  }
}
