package de.heatup.ui;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import javax.swing.SwingConstants;

import de.heatup.logging.Logger;
import de.heatup.ui.statusPanel.Score;
import de.heatup.ui.statusPanel.Timer;


public class StatusPanelAdder{
	private static Color tempBarColor= new Color(0,0,255);
	private static double tempPlus=0.0;
	private static double tempMinus=0.0;
	private static double barSpeed=0.01;
	private static float red;
	private static float green;
	private static float blue; 
	private static Font emulogicheading;
	private static Font emulogictext;
	private static Font emulogictextsmall;
	private static Font ttfBase;
	private static FontLoader fl=new FontLoader();
	private static int vgap=9;
	private static int modifier=-1;
	private static int temping=0;
	private static int manipulations=0;
	private static JLabel labelTempC= new JLabel("§");
	private static JLabel labelTemp= new JLabel("temperature");
	private static JLabel labelScore= new JLabel("score");
	private static JLabel scoreLabel= new JLabel(" ");
	private static JLabel labelPowerUp = new JLabel("! P o w e r U p !");
	private static JLabel powerUpLabel = new JLabel(" ");
	private static JLabel labelTime=new JLabel("Time");
	private static JLabel timeLabel = new JLabel("0");
	private static JPanel panel;
	private static JProgressBar tempBar;
	
	
	
		
	public static void raiseMod(){
		if (modifier==-1){
			modifier=1;
		} else {
		modifier+=1;
		}
	}
	public static void reduceMod(){
		if (modifier==1){
			modifier=-1;
		} else if(modifier==-1){
		} else {
			modifier-=1;
		}
		
	}
	public int getScore(){
		return Score.getScore();
	}
	
	/**
	 * @param newPanel das zu verwendende Panel zur Bearbeitung
	 */
	public static void setPanel(JPanel newPanel){
		newPanel.setLayout(new FlowLayout(FlowLayout.CENTER, 45, vgap));
		panel=newPanel;
	}
	public static void setPUText(String s){
		powerUpLabel.setText(s);
	}
	/**
	 * erhöht die Anzahl Manipulationen
	 */
	public static void addManipulations(){
		manipulations+=1;
		Score.raiseScore(25);
	}
	/**
	 * 
	 * @return anzahl Manipulationen
	 */
	public static int getManipulations(){
		return manipulations;
	}
	
	/**
	 * tick-Methode für das StatusPanel
	 */
	public static void tick() {
		Timer.tickTimer();
		timeLabel.setText(Timer.getMinuteS() + ":" + Timer.getSecondsS());
		scoreLabel.setText(Score.getScoreS());
		
		/**
		 * Temperaturaktualisierung
		 */
		labelTempC.setText(tempBar.getValue() + "°C");
		temping=0;
		if (modifier<0){
			barSpeed=0.01;
			tempMinus+=barSpeed*modifier;
			if (tempMinus<-1){
				temping=-1;
				tempMinus+=1;
			}
		} else if (modifier>0){
			barSpeed=0.02;
			tempPlus+=barSpeed*modifier;
			if (tempPlus>1){
				temping=1;
				tempPlus=-1;
			}
		}
		if (tempBar.getValue()<=30 && modifier==-1) {
		} else {
			tempBar.setValue(tempBar.getValue()+temping);
		}
		if (tempBar.getValue()==110){
			Logger.write(Score.endScore()+"");
		}
		/*
		 * Änderung der Farbe der TempBar
		 */
		red=((float)(((tempBar.getValue())-30)/80.0));
		blue=(1-red);
		tempBarColor=new Color(red, green,blue, (float)0.525);
		tempBar.setForeground(tempBarColor);
		
		
	}
		
		
	
	
	
	
	/**
	 * fügt dem der Klasse übergebenen Panel Objekte hinzu & formatiert diese 
	 */
	public static void createPanel(){
		ttfBase=FontLoader.getFont();
		emulogicheading = ttfBase.deriveFont(Font.PLAIN, 16);
		emulogictext= ttfBase.deriveFont(Font.PLAIN, 12);
		emulogictextsmall=ttfBase.deriveFont(Font.PLAIN, 10);
		
		JPanel tempPanel=new JPanel();
		labelTemp.setFont(emulogicheading);
		labelTemp.setForeground(Color.YELLOW);
		labelTemp.setHorizontalAlignment(SwingConstants.CENTER);
		tempBar= new JProgressBar(0,110);
		tempBar.setValue(30);
		tempBar.setBorderPainted(false);
		labelTempC.setFont(emulogictext);
		labelTempC.setHorizontalAlignment(SwingConstants.CENTER);
		labelTempC.setForeground(Color.YELLOW);
		tempPanel.setLayout(new BorderLayout(0,vgap/2));
		tempPanel.add(labelTemp, BorderLayout.NORTH);
		tempPanel.add(tempBar, BorderLayout.CENTER);
		tempPanel.add(labelTempC, BorderLayout.SOUTH);
		tempPanel.setBackground(Color.BLACK);
				
		JPanel scorePanel=new JPanel();
		labelScore.setFont(emulogicheading);
		labelScore.setForeground(Color.YELLOW);
		labelScore.setHorizontalAlignment(SwingConstants.CENTER);
		scoreLabel.setFont(emulogictext);
		scoreLabel.setForeground(Color.YELLOW);
		scoreLabel.setHorizontalAlignment(SwingConstants.CENTER);
		scorePanel.setLayout(new BorderLayout(0,vgap+2));
		scorePanel.add(labelScore, BorderLayout.NORTH);
		scorePanel.add(scoreLabel, BorderLayout.SOUTH);
		scorePanel.setBackground(Color.BLACK);
		
		JPanel powerUpPanel=new JPanel();
		labelPowerUp.setFont(emulogicheading);
		labelPowerUp.setForeground(Color.YELLOW);
		labelPowerUp.setHorizontalAlignment(SwingConstants.CENTER);
		powerUpLabel.setFont(emulogictextsmall);
		powerUpLabel.setForeground(Color.YELLOW);
		powerUpLabel.setHorizontalAlignment(SwingConstants.CENTER);
		powerUpPanel.setLayout(new BorderLayout(0,vgap+2));
		powerUpPanel.add(labelPowerUp, BorderLayout.NORTH);
		powerUpPanel.add(powerUpLabel, BorderLayout.SOUTH);
		powerUpPanel.setBackground(Color.BLACK);
		//powerUpPanel.setPreferredSize(new Dimension(160,60));
		
		JPanel timePanel=new JPanel();
		labelTime.setFont(emulogicheading);
		//labelTime.setSize(100,10);
		labelTime.setHorizontalAlignment(SwingConstants.CENTER);
		labelTime.setForeground(Color.YELLOW);
		timeLabel.setFont(emulogictext);
		timeLabel.setForeground(Color.YELLOW);
		timeLabel.setHorizontalAlignment(SwingConstants.CENTER);
		timePanel.setLayout(new BorderLayout(0,vgap+2));
		timePanel.add(labelTime, BorderLayout.NORTH);
		timePanel.add(timeLabel, BorderLayout.SOUTH);
		timePanel.setBackground(Color.BLACK);
		
		
		
		panel.add(timePanel);
		panel.add(scorePanel);
		panel.add(tempPanel);
		panel.add(powerUpPanel);
		panel.setBackground(Color.BLACK);
		panel.setVisible(false);
		panel.setVisible(true);
		
		
		
		
	}
		
}

