package ui.view;

import javax.swing.JPanel;
import javax.swing.JProgressBar;
import javax.swing.JLabel;
import java.awt.Font;
import java.awt.Dimension;
import java.awt.Color;
import javax.swing.JSplitPane;
import javax.swing.border.EmptyBorder;

public class FlexibleData extends JPanel {
	private JLabel name_lbl;
	private JProgressBar prodVal;
	private JProgressBar consVal;
	private JLabel lblProdConsVal;
	private JPanel subnetColorPanel;
	public FlexibleData(String name, float prod, float cons, float maxProd, float maxCons) {
		setPreferredSize(new Dimension(570, 100));
		setMinimumSize(new Dimension(550, 100));
		setLayout(null);
		
		name_lbl = new JLabel();
		name_lbl.setFont(new Font("Tahoma", Font.PLAIN, 11));
		name_lbl.setBounds(10, 11, 85, 27);
		setlblName(name);
		add(name_lbl);
		
		JLabel lblFlProd = new JLabel("Flex. Prod.:");
		lblFlProd.setForeground(new Color(0, 204, 51));
		lblFlProd.setBounds(10, 46, 85, 27);
		add(lblFlProd);
		
		JLabel lblFlexCons = new JLabel("Flex. Cons.:\r\n");
		lblFlexCons.setForeground(new Color(255, 0, 0));
		lblFlexCons.setBounds(188, 46, 85, 27);
		add(lblFlexCons);
		
		JLabel lblProdCons = new JLabel("Prod./Cons.:");
		lblProdCons.setForeground(new Color(218, 165, 32));
		lblProdCons.setBounds(365, 46, 113, 27);
		add(lblProdCons);
		
		prodVal = new JProgressBar();
		setProd(maxProd, prod);
		prodVal.setBounds(94, 48, 85, 24);
		prodVal.setBorder(new EmptyBorder(0, 0, 0, 0));
		prodVal.setStringPainted(true);
		prodVal.setForeground(new Color(0, 204, 51));
		add(prodVal);
		
		consVal = new JProgressBar();
		setCons(maxCons, cons);
		consVal.setBounds(270, 46, 85, 24);
		consVal.setBorder(new EmptyBorder(0, 0, 0, 0));
		consVal.setStringPainted(true);
		consVal.setForeground(Color.RED);
		add(consVal);
		
		lblProdConsVal = new JLabel();
		setProdConsVal(prod, cons);
		lblProdConsVal.setBounds(453, 46, 103, 24);
		add(lblProdConsVal);
		
		subnetColorPanel = new JPanel();
		subnetColorPanel.setBackground(new Color(255, 255, 255));
		subnetColorPanel.setForeground(new Color(0, 0, 0));
		subnetColorPanel.setBounds(94, 11, 31, 27);
		add(subnetColorPanel);
	}
	
	public void setProd(float max, float current){
		int val = prodVal.getMaximum();
		if(max != 0){
		val = Math.round((current/max)*prodVal.getMaximum());
		}
		prodVal.setValue(val);
		prodVal.setString(Float.toString(current));
	}
	
	public void setCons(float max, float current){
		int val = prodVal.getMaximum();
		if(max != 0){
		val = Math.round((current/max)*prodVal.getMaximum());
		}
		consVal.setValue(val);
		consVal.setString(Float.toString(current));
	}
	
	public void setProdConsVal(float prod, float cons){
		if(cons != 0){
			lblProdConsVal.setText(Float.toString((prod/cons)*(-1)));
		}else if(prod == 0){
			lblProdConsVal.setText(Float.toString(0));
		}
		else{
			lblProdConsVal.setText(Character.toString('\u221e'));
		}
	}
	
	public void setlblName(String name){
		name_lbl.setText(name);
	}
	
	public JPanel getColorPanel(){
		return subnetColorPanel;
	}
	
	public JLabel getNamelbl(){
		return name_lbl;
	}
}
