import java.io.File;
import java.util.ArrayList;
import java.awt.event.*;
import javax.swing.JMenuItem;
import javax.swing.JFileChooser;

public class MenuFilesListener implements ActionListener {
	//#################################
	private DBManager		DBman;
	private MyFiles 		files;
	private MyVideos_GUI 	gui;
	JFileChooser 			fc;
	Thread 					asd;
	//#################################
	public MenuFilesListener(MyFiles f, DBManager db) {
		files = f;
		DBman = db;
	}
	public void addGUI(MyVideos_GUI g) {
		gui = g;
	}
	//#################################
	public void actionPerformed(ActionEvent e) {
		JMenuItem menuItem = (JMenuItem)(e.getSource());
		String text = menuItem.getText();
		if(text.equals("Add Movies Folder")) {
			fc = new JFileChooser();
			fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
			int returnVal = fc.showOpenDialog(null);
			if (returnVal == JFileChooser.APPROVE_OPTION) {
				File file = fc.getSelectedFile();
				asd = new Thread(new Runnable() {
					@Override
					public void run() {
						files.addFiles(file);
					}
				});
				asd.start();
			}
			else {
				System.out.println("Command cancelled by user.\n");
			}
			
		}
		if(text.equals("Add Movie File")) {
			fc = new JFileChooser();
			int returnVal = fc.showOpenDialog(null);
			if (returnVal == JFileChooser.APPROVE_OPTION) {
				File file = fc.getSelectedFile();
				files.addFiles(file);
			}
			else {
				System.out.println("Command cancelled by user.\n");
			}
		}
		if(text.equals("Close")) {
			DBman.closeDB();
			gui.dispose();
		}
	}
}
