package de.heatup.ui.menu;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.TextField;

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

import de.heatup.ui.FontLoader;

public class SaveScorePanel {
	
	private static JPanel saveScorePanel = new JPanel();
	
	// 
	private static JPanel headingPanel, dividerPanel, formPanel;
	private static JLabel headingLabel, dividerLabel, scoreLabel;
	private static TextField nameField;
	
	// Font loader and font Settings
	private static FontLoader fl = new FontLoader();
	private static Font ttfbase, emulogicHeading, emulogicDivider, emulogicSmall;
	
	private static int score = 0;
	
	public SaveScorePanel() {
		
		ttfbase = FontLoader.getFont();
		emulogicHeading = ttfbase.deriveFont(Font.PLAIN, 40);
		emulogicDivider = ttfbase.deriveFont(Font.PLAIN, 20);
		emulogicSmall = ttfbase.deriveFont(Font.PLAIN, 18);
		
		saveScorePanel.setSize(new Dimension(800, 600));
		saveScorePanel.setBackground(Color.BLACK);
		saveScorePanel.setVisible(true);
		
		initHeadingPanel();
		saveScorePanel.add(headingPanel);
		saveScorePanel.add(dividerPanel);
				
	}
	
	private static void initHeadingPanel() {
		
		headingPanel = new JPanel();
		headingPanel.setSize(new Dimension(800, 50));
		headingPanel.setBackground(Color.BLACK);
		headingPanel.setFocusable(false);
		headingPanel.setVisible(true);
		
		headingLabel = new JLabel();
		headingLabel.setFont(emulogicHeading);
		headingLabel.setForeground(Color.YELLOW);
		headingLabel.setBackground(Color.BLACK);
		headingLabel.setFocusable(false);
		headingLabel.setText("Heatup");
		
		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.setFont(emulogicDivider);
		dividerLabel.setForeground(Color.YELLOW);
		dividerLabel.setBackground(Color.BLACK);
		dividerLabel.setFocusable(false);
		dividerLabel.setText("--------------------------------");
		
		dividerPanel.add(dividerLabel);
	}
	
	
	private static void initFormPanel() {
		formPanel = new JPanel();
		formPanel.setSize(new Dimension(800, 400));
		formPanel.setBackground(Color.BLACK);
		formPanel.setFocusable(true);
		formPanel.setVisible(true);
		
		// 
		nameField = new TextField("Name", 25);
		nameField.setEditable(true);
		nameField.setFont(emulogicSmall);
		
		//
		scoreLabel = new JLabel();
		scoreLabel.setFont(emulogicSmall);
		scoreLabel.setForeground(Color.YELLOW);
		scoreLabel.setBackground(Color.BLACK);
		scoreLabel.setFocusable(false);
		
		
		JPanel nameFormPanel = new JPanel();
		nameFormPanel.setSize(new Dimension(800, 300));
		nameFormPanel.setLayout(new GridLayout(2, 1));
		nameFormPanel.setBackground(Color.BLACK);
		nameFormPanel.setFocusable(true);
		nameFormPanel.setVisible(true);
		
		nameFormPanel.add(nameField);
		
		formPanel.add(nameFormPanel);
	}
	
	public static void setScoreLabelText(int score) {
		SaveScorePanel.score = score;
		scoreLabel.setText("Score : " + SaveScorePanel.score);
		
		initFormPanel();
		formPanel.add(scoreLabel);
		saveScorePanel.add(formPanel);
	}
	
	public static void setScore(int score) {
		SaveScorePanel.score = score;
	}
	
	public static int getScore() {
		return score;
	}
	
	public static JPanel getSaveScorePanel() {
		return saveScorePanel;
	}
	
	public static void setSaveScorePanel(JPanel saveScorePanel) {
		SaveScorePanel.saveScorePanel = saveScorePanel;
	}
}
