package hh.dejsem.hack;

import android.view.ContextMenu;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;

import java.util.ArrayList;

import hh.lib.D;

public class HackPanelMenu {

	enum PanelMenuItem {
		M1() { void action(HackContextMenu target) throws Exception { target.handleMenuItem11(); } },
		M2("zkouška 2"),
		M3("zkouška 3") { void action(HackContextMenu target) throws Exception { target.handleMenuItem33(); } };

		final int i;
		final String title;
		void action(HackContextMenu target) throws Exception {};

		PanelMenuItem() {
			i = ordinal();
			title = name();
		}
		PanelMenuItem(String n) {
			i = ordinal();
			this.title = n;
		}
	}

	D d;
	ArrayList<PanelMenuItem> items = new ArrayList<PanelMenuItem>();

	HackPanelMenu(D d) {
		this.d = d.klon(this);
		for(PanelMenuItem p: PanelMenuItem.values()) items.add(p.ordinal(), p);
	}

	void createContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
		d.l("createContextMenu");
		menu.add(Menu.NONE, PanelMenuItem.M1.ordinal(), Menu.NONE, PanelMenuItem.M1.title);
		menu.add(Menu.NONE, PanelMenuItem.M2.ordinal(), Menu.NONE, PanelMenuItem.M2.title);
		menu.add(Menu.NONE, PanelMenuItem.M3.ordinal(), Menu.NONE, PanelMenuItem.M3.title);
		menu.add(Menu.NONE, 22, Menu.CATEGORY_CONTAINER + 1, "expl. zkouška 2");
		menu.add(Menu.NONE, 33, Menu.CATEGORY_CONTAINER + 2, "expl. zkouška 3");
	}

	boolean handleContextItemSelected(MenuItem item, HackContextMenu target) {
		d.l("handleContextItemSelected, item=" + items.get(item.getItemId()));
		if(item.getItemId() < items.size())
			try { items.get(item.getItemId()).action(target); }
			catch(Exception e) {}
			finally { return true; }
		return false;
	}
}
