package View;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;

import Controller.Controller;

public class MenuBar extends JMenuBar {
    
    /**
	 *  Class which creates represents the Menu bar of the program. It ahs just the constructor and a few listeners for the menu items.
	 */
	private static final long serialVersionUID = 1L;

	private Controller controller;
	
	public MenuBar(Controller controller) {
        
		this.controller=controller;
        // Define and add the three drop down menus to the menubar
        JMenu fileMenu = new JMenu("File");
        JMenu viewMenu = new JMenu("View");
        JMenu helpMenu = new JMenu("Help");
        this.add(fileMenu);
        this.add(viewMenu);
        this.add(helpMenu);
        
        // Create and add the items for the File drop down menu.
        // Some are still grayed as they don't hold any functionality yet
        final JMenuItem newAction = new JMenuItem("New");
        newAction.setEnabled(false);
        final JMenuItem paraAction = new JMenuItem("Load parameters");
        paraAction.setEnabled(false);
        final JMenuItem sceneAction = new JMenuItem("Load Scenes");
        sceneAction.setEnabled(false);
        final JMenuItem openAction= new JMenuItem("Open log flile");
        openAction.setEnabled(false);
        final JMenuItem saveAction= new JMenuItem("Save to log");
        final JMenuItem exitAction= new JMenuItem("Exit");
        
        // Create and add the items for the View drop down menu.
        //TODO add the action listeners
        final JCheckBoxMenuItem para=new JCheckBoxMenuItem("Parameters"); 
        para.setSelected(true);
        para.setEnabled(false);
        final JCheckBoxMenuItem scenes=new JCheckBoxMenuItem("Scenes"); 
        scenes.setSelected(true);
        scenes.setEnabled(false);
        final JCheckBoxMenuItem woLeOvTi=new JCheckBoxMenuItem("Words learned over time"); 
        woLeOvTi.setSelected(true);
        woLeOvTi.setEnabled(false);
        final JCheckBoxMenuItem woCoSc=new JCheckBoxMenuItem("Word Comprehension Score"); 
        woCoSc.setSelected(true);
        woCoSc.setEnabled(false);
        final JCheckBoxMenuItem table=new JCheckBoxMenuItem("Wordtable"); 
        table.setSelected(true);
        table.setEnabled(false);
        
        // Create and add the items for the Help drop down menu.
        //TODO write the Help Contents and add a link here
        final JMenuItem handbook= new JMenuItem("Handbook");
        handbook.setEnabled(false);
        final JMenuItem context=new JMenuItem("Context help");
        context.setEnabled(false);
        final JMenuItem about= new JMenuItem("About");
        about.setEnabled(false);
        
        
        //add the item to the drop down menus
        fileMenu.add(newAction);
        fileMenu.add(paraAction);
        fileMenu.add(sceneAction);
        fileMenu.add(openAction);
        fileMenu.addSeparator();
        fileMenu.add(saveAction);
        fileMenu.add(exitAction);
        
        viewMenu.add(para);
        viewMenu.add(scenes);
        viewMenu.add(woLeOvTi);
        viewMenu.add(woCoSc);
        viewMenu.add(table);
        
        helpMenu.add(handbook);
        helpMenu.add(context);
        helpMenu.add(about);
        

        //finally add the ActionListeners
        exitAction.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				System.exit(0);
			}
		});
        
        saveAction.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				MenuBar.this.controller.saveCompleteResults();
			}
		});
        
        
    }
   
}
