package jatek0003;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;

import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;

import customize.Custom;

import jatek.JatekPanel;

public class Jatek0003Panel extends JatekPanel {

	/**
	 * 
	 */
	private static final long serialVersionUID = 6962342949994555272L;
	protected JPanel inputPanel=new JPanel(new BorderLayout());
	protected JPanel outputPanel=new JPanel();
	protected JScrollPane js;
	
	protected JLabel description = new JLabel("");
	protected JLabel gameInputContent = new JLabel("");
	protected JLabel gameResults=new JLabel("");
	
	private JButton a1=new JButton("A1");
	private JButton a2=new JButton("A2");
	private JButton indifferent=new JButton("Indifferens");
	private JComboBox sex,age;
	
	public Jatek0003Panel(){
		super();
		this.setLayout(new BoxLayout(this,BoxLayout.Y_AXIS));
		
		//inputPanel tartalma
		JPanel in = new JPanel();
		JLabel gameDescription=new JLabel("<html><p>Inputok</p><p>A játék leírása</p>");
        JLabel gameInput=new JLabel("A játék inputja");

		Box box1 = new Box(BoxLayout.Y_AXIS);
		box1.add(Box.createVerticalStrut(15));
	    box1.add(gameDescription);
	    box1.add(Box.createVerticalStrut(15));
	    box1.add(description);
	    box1.add(Box.createVerticalStrut(15));
	    box1.add(gameInput);
	    box1.add(gameInputContent);
	    box1.add(Box.createVerticalStrut(20));
	    box1.add(Box.createHorizontalGlue());
	    in.add(box1);
	    //in.setBorder(BorderFactory.createRaisedBevelBorder());
	    
	    JPanel form = new JPanel();
	    JLabel sexInput=new JLabel("Nem: ");sexInput.setAlignmentX(LEFT_ALIGNMENT);
        JLabel ageInput=new JLabel("Kor: ");ageInput.setAlignmentX(LEFT_ALIGNMENT);
        JLabel formInput=new JLabel("További adatok megadása");formInput.setAlignmentX(LEFT_ALIGNMENT);
        String[] sexes={"nem válaszolok","férfi","nő"};
	    sex  = new JComboBox(sexes);
	    sex.setMaximumSize(new Dimension(150,20));
	    sex.setSelectedIndex(0);
	    sex.setAlignmentX(LEFT_ALIGNMENT);
	    Object[] ages=new Object[86];
	    ages[0]="nem válaszolok";
        for(int i = 1;i<ages.length;i++){
        	ages[i]=i+15;
        }
	    age=new JComboBox(ages);
	    age.setSelectedIndex(0);
	    age.setMaximumSize(new Dimension(150,20));
	    age.setAlignmentX(LEFT_ALIGNMENT);
	    Box formB = new Box(BoxLayout.Y_AXIS);
	    formB.add(formInput);
	    formB.add(Box.createVerticalStrut(15));
	    formB.add(sexInput);
	    formB.add(sex);
	    formB.add(Box.createVerticalStrut(15));
	    formB.add(ageInput);
	    formB.add(age);
	    formB.add(Box.createVerticalStrut(15));
	    form.add(formB);
	    
	    JPanel response = new JPanel();
	    a1.setEnabled(false);
	    a2.setEnabled(false);
	    indifferent.setEnabled(false); 
	    
		Box res = new Box(BoxLayout.X_AXIS);
		res.add(a1);
		res.add(Box.createHorizontalStrut(15));
		res.add(a2);
		res.add(Box.createHorizontalStrut(15));
		res.add(indifferent);
	    response.add(res);
	    //response.setBorder(BorderFactory.createRaisedBevelBorder());

	    inputPanel.add(in,BorderLayout.NORTH);
	    inputPanel.add(response,BorderLayout.CENTER);
	    inputPanel.add(form,BorderLayout.SOUTH);
	    inputPanel.setMaximumSize(new Dimension(550,500));
	    inputPanel.setBorder(BorderFactory.createLineBorder(Color.decode(Custom.getBorderColor()),Custom.getBorderThickness()));
	    
	    //outputPanel tartalma
	    Box box2 = Box.createVerticalBox();
	    box2.setPreferredSize(new Dimension(550,500));
        gameResults=new JLabel("A számított eredmények");
        js=new JScrollPane(gameResults);
        box2.add(js);
        box2.add(Box.createVerticalStrut(10));
        outputPanel.add(box2);
        outputPanel.setBorder(BorderFactory.createLineBorder(Color.decode(Custom.getBorderColor()),Custom.getBorderThickness()));
        gameResults.setForeground(Color.decode(Custom.getBaseTextColor()));
	    this.add(inputPanel);
	    this.add(outputPanel);
	    setPanel("input");
	}
	
	@Override
	public void showMessage(String messageType){
		if("loaded".equals(messageType)){
			JOptionPane.showMessageDialog(this,"Sikeres betöltés. Kattintson az OK gombra!",
		         "Betöltés",JOptionPane.INFORMATION_MESSAGE);
		}else if("mysqlError".equals(messageType)){
			JOptionPane.showMessageDialog(this,"Nem sikerült az adatokat elmenteni az adatbázisba!",
			         "Hiba",JOptionPane.ERROR_MESSAGE);
		}else if("mysqlOK".equals(messageType)){
			JOptionPane.showMessageDialog(this,"Az adatokat sikeresen mentettük!",
			         "Mentés",JOptionPane.INFORMATION_MESSAGE);
		}else if("toExcelProblem".equals(messageType)){
			JOptionPane.showMessageDialog(this,"Az eredményeket addig nem lehet elmenteni, amíg a játék véget nem ért!",
			         "Figyelmeztetés",JOptionPane.WARNING_MESSAGE);
		}
	}
	
	public JPanel getInputPanel() {
		return inputPanel;
	}

	public void setInputPanel(JPanel inputPanel) {
		this.inputPanel = inputPanel;
	}

	public JPanel getOutputPanel() {
		return outputPanel;
	}

	public void setOutputPanel(JPanel outputPanel) {
		this.outputPanel = outputPanel;
	}

	public JLabel getDescription() {
		return description;
	}

	public void setDescription(JLabel description) {
		this.description = description;
	}

	public JLabel getGameInputContent() {
		return gameInputContent;
	}

	public void setGameInputContent(JLabel gameInputContent) {
		this.gameInputContent = gameInputContent;
	}

	public JLabel getGameResults() {
		return gameResults;
	}

	public void setGameResults(JLabel gameResults) {
		this.gameResults = gameResults;
	}
	public JButton getA1() {
		return a1;
	}

	public void setA1(JButton a1) {
		this.a1 = a1;
	}

	public JButton getA2() {
		return a2;
	}

	public void setA2(JButton a2) {
		this.a2 = a2;
	}

	public JButton getIndifferent() {
		return indifferent;
	}

	public void setIndifferent(JButton indifferent) {
		this.indifferent = indifferent;
	}

	public JComboBox getSex() {
		return sex;
	}

	public void setSex(JComboBox sex) {
		this.sex = sex;
	}

	public JComboBox getAge() {
		return age;
	}

	public void setAge(JComboBox age) {
		this.age = age;
	}

	@Override
	public void setPanel(String s){
		if(s.equals("input")) {
			//true
			inputPanel.setVisible(true);
			//false
			outputPanel.setVisible(false);
			js.setVisible(false);
		}
		else if(s.equals("output")) {
			//true
			outputPanel.setVisible(true);
			js.setVisible(true);
			//false
			inputPanel.setVisible(false);
		}
	}
	
}
