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


package 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;

//import javafx.scene.media.AudioClip;

public class NavigationPanel extends JPanel implements ActionListener
{
    //PANEL
    JPanel topButtonPanel;
    JPanel centerPanel;
    JPanel buttonPanel;
    
    //Top
    JComboBox miningSelect;
    int selectedMining;
    
    //Buttom
    JButton voiceRepeat;
    JButton voiceStop;
    JButton yes;
    
    String menuInJapanese[];
    
    
    //VARIABLE
    Control control;
    SettingData settingData;
    
    NavigationControl navigationControl;
    
    //ACTION
    boolean autoSet;
    
    //SOUND

    

    
    NavigationPanel(Control control)
    {
        setLayout(new BorderLayout());
        
        settingData = control.sp1;
        this.control = control;
        
        this.navigationControl = control.navigationControl;

        menuInJapanese = FILEIO.TextFileAllReadCodeArray(new File(settingData.absolutePath + "source" + File.separator + "japaneseText" + File.separator+ "JapaneseNavigation.txt"));
        
        

        
        centerPanel = new JPanel();
        centerPanel.setBackground(new Color(0, 0, 0));
        add(centerPanel);
        
        topButtonPanel = new JPanel(new BorderLayout());
        topButtonPanel.setBackground(new Color(0, 0, 0));
        add(topButtonPanel, BorderLayout.NORTH);
        
        buttonPanel = new JPanel(new GridLayout(1,3));
        buttonPanel.setBackground(new Color(0, 0, 0));
        add(buttonPanel, BorderLayout.SOUTH);
        
        
        String names[] = new String[10];
        if(settingData.inJapanese)
            for(int i=0;i<10;i++)
                names[i] = (i+1)+". " + menuInJapanese[i];
        else
            for(int i=0;i<10;i++)
                names[i] = "STEP "+(i+1);
        
        miningSelect = new JComboBox(names);
        miningSelect.setSelectedIndex(0);
        miningSelect.addActionListener(this);
        miningSelect.setMaximumRowCount(11);
        topButtonPanel.add(miningSelect);
        
        if(settingData.inJapanese)
        {
            voiceRepeat = new JButton(menuInJapanese[10]);
            voiceStop = new JButton(menuInJapanese[11]);
            yes = new JButton(menuInJapanese[12]);
        }
        else
        {
            voiceRepeat = new JButton("REPEAT");
            voiceStop = new JButton("STOP");
            yes = new JButton("YES");
        }
        
        voiceRepeat.setFont(new Font(settingData.fontName, Font.BOLD, 12));
        voiceStop.setFont(new Font(settingData.fontName, Font.BOLD, 12));
        yes.setFont(new Font(settingData.fontName, Font.BOLD, 12));
        
        voiceRepeat.setBackground(Color.GREEN);
        voiceStop.setBackground(Color.GREEN);
        yes.setBackground(Color.GREEN);
        
        voiceRepeat.addActionListener(this);
        voiceStop.addActionListener(this);
        yes.addActionListener(this);
        
        buttonPanel.add(voiceRepeat);
        buttonPanel.add(voiceStop);
        buttonPanel.add(yes);
        
        yes.setEnabled(false);  //can push when TETDM accepts
    }

    public void actionPerformed(ActionEvent e)
    {
        if(autoSet == true)
            return;
    
        String buttonName = control.getButtonName(e);
        ACTIONLOG.writeButtonLog("NAVIGATIONPANEL", buttonName, (Component)e.getSource());
        
        if(e.getSource() == voiceRepeat)
        {
            navigationControl.soundPlay();
        }
        
        if(e.getSource() == voiceStop)
        {
            navigationControl.soundSkip();
            yes.setEnabled(true);///////////////// Set Enabled only when the action is attached
        }
        
//        if(e.getSource() == yes)
//        {
//            navigationControl.navigateByTheGuidance();
//            yes.setEnabled(false);
//        }
        
        if(e.getSource() == miningSelect)
        {
            navigationControl.setStep( miningSelect.getSelectedIndex() );
        }
    }

    public void closeWindow()
    {
        //setSelected(false);
    }
    
}
