package de.jaujau.gui;
import java.awt.CardLayout;
import java.awt.Color;

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;

import de.jaujau.daten.Spielerverwaltung;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.FlowLayout;
import javax.swing.SwingConstants;
import javax.swing.table.DefaultTableModel;

import java.awt.Font;


public class Menue_GUI
extends JPanel {
	
	private CardLayout cardLayout;
	
	private JPanel panel1, panel2, panel3;
	private int sizemenu = 270;
	
	
	// Konstruktor
	public Menue_GUI(Spielerverwaltung speicherung) {
		
		setBorder(javax.swing.BorderFactory.createTitledBorder("Content"));
		
		cardLayout = new CardLayout();

		this.setLayout(cardLayout);
		
		// Objekte der Panel erzeugen, die angezeigt werden sollen
		panel1 = new JPanel();
		panel1.setName("panel1");
		panel2 = new JPanel();
		panel2.setName("panel2");
		panel3 = new JPanel();
		panel3.setName("panel3");
		
		panel1.setBackground(Color.YELLOW);
		panel2.setBackground(Color.WHITE);
		panel3.setBackground(Color.GREEN);
		
		JLabel label1 = new JLabel("Startseite");
		label1.setAlignmentX(Component.CENTER_ALIGNMENT);
		JLabel label2 = new JLabel("Highscore");
		label2.setFont(new Font("Tahoma", Font.PLAIN, 18));
		label2.setHorizontalAlignment(SwingConstants.CENTER);
		label2.setAlignmentX(Component.CENTER_ALIGNMENT);
		
		
		renderHighscore(); //Highscore Tabelle wird geladen
		panel2.setVisible( true );

		
		
		JLabel label3 = new JLabel("Panel 3: Spiel");
		panel2.add(label2, BorderLayout.NORTH);
		panel3.add(label3);
		
		this.add(panel1, "Start");
		panel1.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
		panel1.add(label1);
		
		JLabel lblNewLabel_1 = new JLabel("New label");
		panel1.add(lblNewLabel_1);
		this.add(panel2, "Highscore");
		this.add(panel3, "Spiel");
		
		JPanel panel4 = new JPanel();
		panel4.setBackground(Color.LIGHT_GRAY);
		this.add(panel4, "Einstellungen");
		
		JLabel lblNewLabel = new JLabel("Einstellungen");
		panel4.add(lblNewLabel);
	
	}
	
	
	public void showPanel(String panel) {
		 
		cardLayout.show(this, panel);
 
    }
	
	
	public void renderHighscore() {
		
		String[][] rowData = {{ "Seb", "245" }, { "Elmo", "240" }, { "Moritz","220" }, { "Alaa Aldin", "217" }, {"Fabian", "215"}}; //Bsp. Datensatz muss noch entfernt werden.

	    String[] columnNames =  {"Name", "Punkte"};
	    panel2.setLayout(new BorderLayout(0, 0));
	    JTable table = new JTable(); //Leere Tabelle
	    DefaultTableModel tableModel = new DefaultTableModel(rowData, columnNames) { //Tabelle formatieren und Zellen nicht bearbeitbar machen
			private static final long serialVersionUID = 838285314713L;
	        public boolean isCellEditable(int row, int column) {
	           //all cells false
	           return false;
	        }
	    };
	    table.setAutoCreateRowSorter(true); //Tabelle Sortierbar durch Tabellenkopf
	    table.getTableHeader().setReorderingAllowed(false); //Tabelle nicht mehr drag and drop
	    table.setModel(tableModel);
	    
	    
	    panel2.add( new JScrollPane( table ) );
		
		
	}

}