//
// Core Program for TETDM 
// ItemPanel.java Version 1.00
// Copyright(C) 2015-2018 TETDM CORE MEMBER ALL RIGHTS RESERVED.
// This program is provided under the license.
//

package source.GameMode;

import source.*;
import source.TextData.*;
import source.Utility.*;

import java.io.File;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.text.*;
import java.util.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.GroupLayout.Alignment;


public class ItemPanel extends JPanel implements ActionListener
{
	ExpPanel exppanel;

	JPanel allTopPanel;
	JPanel middlePanel;
	
	
	JPanel buttonPanel;

	JPanel checkPanel;
	JPanel labelPanel;
	
	
	//Top
	JLabel message;

    //Middle
	JScrollPane scroll[];
	
    JPanel checkBoxPanel1; 		
    JPanel checkBoxPanel2;	
    
	//checkBoxPanel1
    JLabel boxLabel[];    
   	//JCheckBox setBoxA[];
	ButtonGroup modeGroup;	
	

	

    ButtonGroup leftGroup;
	
	String posString[] = new String[9];
	String periodString[] = new String[3];
	String sunaString;
	

	//checkBoxPanel2
   	//JCheckBox setBoxB[];	//currently not used, these are prepared for task execution

	
	//Buttom	

	//JButton bt40 = new JButton();
	
	static JButton mp = new JButton();	
	
	int fontsize = 16;
	
	public static int mpnumber = 0;
	String menuInJapanese[];
	
	SettingData settingData;
	
	boolean autoSet;
	Control control;
	PopUpForItem popUp;
	
	ImageIcon icon,smallIcon;
	Image smallImg;	
	
	ItemPanel(Control control, PopUpForItem popUp)
	{
		setLayout(new BorderLayout());
		
		settingData = control.sp1;
		this.control = control;
		this.popUp = popUp;
		
		menuInJapanese = FILEIO.TextFileAllReadCodeArray(new File(control.absolutePath + "source" + File.separator + "GameMode" + File.separator+ "Item.txt"));		
		
		//ALL
		allTopPanel = new JPanel();
        	allTopPanel.setBackground(Color.blue);
		add(allTopPanel, BorderLayout.NORTH);

		message = new JLabel();
		message.setFont(new Font(settingData.fontName, Font.BOLD, fontsize+2));
		message.setForeground(Color.white);
		
		setTitleNames();
		allTopPanel.add(message);

		

		
		//MIDDLE
		middlePanel = new JPanel();		
//		middlePanel.setLayout(new GridLayout(2,1));
		middlePanel.setLayout(new GridLayout(1,1));		
        add(middlePanel);
        scroll = new JScrollPane[2];
        
        //MIDDLE-INSIDE
		
		checkPanel = new JPanel(new GridLayout(3,1));
		labelPanel = new JPanel(new GridLayout(3,1));
		checkPanel.setBackground(new Color(0x7f,0xff,0xd4));
		checkPanel.setBackground(Color.blue);
		labelPanel.setBackground(new Color(0x7f,0xff,0xd4));
		labelPanel.setBackground(Color.green);
		
		int iconSize = 70;
		icon = new ImageIcon(control.absolutePath+"source"+File.separator+"GameMode"+File.separator+"image"+File.separator+"mp.png");
			
		smallImg = icon.getImage().getScaledInstance(iconSize, iconSize, Image.SCALE_SMOOTH);
		smallIcon = new ImageIcon(smallImg);			
		mp = new JButton("",smallIcon);
		
		//game mode button
		//bt80.setIcon(new ImageIcon(control.absolutePath+"source"+File.separator+"image"+File.separator+"item.png"));
		//bt80.setSelectedIcon(new ImageIcon(control.absolutePath+"source"+File.separator+"image"+File.separator+"character100.png"));		
		mp.setBackground(new Color(0x7f,0xff,0xd4));
		mp.setBackground(Color.white);
		mp.setText("   "  + menuInJapanese[1] + mpnumber);
		
		mp.addActionListener(this);
		
		
		createSetPanel();
		//initializeSetBox();		

		
			//bt80.setTextSize(32.0);
			//autoSet = true;
			//bt80.setSelected(true);
			//autoSet = false;
	  
	

		


		//BOTTOM
		buttonPanel = new JPanel(new GridLayout(2,1));
		add(buttonPanel, BorderLayout.SOUTH);	
		buttonPanel.setBackground(Color.white);		


	
		
		//bt40.addActionListener(this);
//		bt40.setBackground(Color.GREEN);
		//buttonPanel.add(bt40);
	}
    
	public void createSetPanel()
	{
        //CheckBox
        boxLabel = new JLabel[4];
        //setBoxA = new JCheckBox[4];
        //setBoxB = new JCheckBox[5];


        for(int i=0;i<4;i++)
        {
            boxLabel[i] = new JLabel();
            boxLabel[i].setFont(new Font(settingData.fontName, Font.BOLD, fontsize));
        }
		modeGroup = new ButtonGroup();		
        
        checkBoxPanel1 = new JPanel(new BorderLayout());
		checkBoxPanel1.setBackground(new Color(0x7f,0xff,0xd4));//green
//		checkBoxPanel1.setLayout(new GridLayout(4,2,5,-2));		

        
		/*for(int i=0;i<4;i++)
		{
            labelPanel.add(boxLabel[i]);
            
			setBoxA[i] = new JCheckBox();
			setBoxA[i].setBackground(new Color(0x7f,0xff,0xd4));//green
			setBoxA[i].addItemListener(this);
			checkPanel.add(setBoxA[i]);
			
			modeGroup.add(setBoxA[i]);
		}
		*/
		labelPanel.add(mp);
        
		checkBoxPanel1.add(labelPanel);
		checkBoxPanel1.add(checkPanel, BorderLayout.WEST);		
		
		
        scroll[0] = new JScrollPane(checkBoxPanel1);
        middlePanel.add(scroll[0]);
        


        
        //BOX continue
        checkBoxPanel2 = new JPanel();
		checkBoxPanel2.setBackground(Color.pink);
		checkBoxPanel2.setLayout(new GridLayout(5,1,5,-2));
        
		//for(int i=0;i<5;i++)
		//{
			//setBoxB[i] = new JCheckBox();
			//setBoxB[i].addItemListener(this);
			//setBoxB[i].setBackground(Color.white);
			//checkBoxPanel2.add(setBoxB[i]);
		//}
        
        scroll[1] = new JScrollPane(checkBoxPanel2);
 //       middlePanel.add(scroll[1]);    
	}

	public void setTitleNames()
	{
		if(settingData.inJapanese)
			message.setText(menuInJapanese[0]);
		else
			message.setText("Item");
	}
	



	//Action listener
	public void actionPerformed(ActionEvent e)
    {
        if(autoSet == true)
            return;		
		
		JLabel label = new JLabel(menuInJapanese[3]);
		
		// Game Mode
	if(e.getSource() == mp && mpnumber > 0)
	{
	
	int option = JOptionPane.showConfirmDialog(this,label,menuInJapanese[4],JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE);
	if (option == JOptionPane.YES_OPTION){
		control.ex1.stamina = 100.0;
	
	if(control.ex1.rank >= 1000 ){
	control.ex1.stamina2 = 100;
	control.ex1.stamina3 = 100;
	}
	
	if(control.ex1.rank < 1000 && control.ex1.rank >= 100  ){
	control.ex1.stamina2 = control.ex1.rank/10;
	control.ex1.stamina3 = (control.ex1.rank/10);
	}
	
	if(control.ex1.rank < 100 ){
	control.ex1.stamina2 = 10;
	control.ex1.stamina3 = 10;
	}
	
	if(mpnumber > 0) mpnumber = mpnumber - 1;
	mp.setText("   "  + menuInJapanese[1] + mpnumber);
	
	
	if(control.expPanel != null) control.expPanel.repaint();
	}
	
	}
	
		
		
	}
	
	public void closeWindow()
	{		
	exppanel.item.setSelected(false);
        exppanel.closePopForItem();
	
	}
	
	
	
	
}
