package managedbean.common;

import java.io.Serializable;

import javax.annotation.PostConstruct;
import javax.enterprise.context.RequestScoped;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.inject.Named;

import org.primefaces.model.menu.DefaultMenuItem;
import org.primefaces.model.menu.DefaultMenuModel;
import org.primefaces.model.menu.DefaultSubMenu;
import org.primefaces.model.menu.MenuModel;

@Named("menuView")
@RequestScoped
public class MenuMBean implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private MenuModel model;

	@PostConstruct
	public void init() {
		model = new DefaultMenuModel();

		// First submenu
		DefaultSubMenu firstSubmenu = new DefaultSubMenu("Dynamic submenu");
		DefaultMenuItem item = new DefaultMenuItem("External", "", "www.google.com");
//		item.setUrl("www.google.com");
		firstSubmenu.getElements().add(item);

		model.getElements().add(firstSubmenu);

		// Second submenu
		DefaultSubMenu secondSubmenu = new DefaultSubMenu("Dynamic Actions");

		item = new DefaultMenuItem("Save", "pi pi-save");
		item.setCommand("#{menuView.save}");
		item.setUpdate("messages");
		secondSubmenu.getElements().add(item);

		item = new DefaultMenuItem("Delete", "pi pi-times");
		item.setCommand("#{menuView.delete}");
		item.setAjax(false);
		secondSubmenu.getElements().add(item);

		item = new DefaultMenuItem("Redirect", "pi pi-search");
		item.setCommand("#{menuView.redirect}");
		secondSubmenu.getElements().add(item);

		model.getElements().add(secondSubmenu);
	}

	public MenuModel getModel() {
		return model;
	}

	public void save() {
		addMessage("Success", "Data saved");
	}

	public void update() {
		addMessage("Success", "Data updated");
	}

	public void delete() {
		addMessage("Success", "Data deleted");
	}

	public String goManageSpecialties() {

		return "ManageSpecialties";
	}

	public String goVisit() {
		return "VisitView";
	}

	public String goMedicalTests() {
		return "MedicalTests";
	}

	public String goListSpecialistDoctors() {
		return "header";
	}

	public String goListSpecialistDoctorsBySpecialty() {
		return "header";
	}

	public String goListaFamilyDoctors() {
		return "header";
	}

	public String goChangeDoctor() {
		return "header";
	}

	public String goChangeCAP() {
		return "header";
	}

	public String goAddPatient() {
		return "profile/AddPaciente";
	}

	public void addMessage(String summary, String detail) {
		FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, summary, detail);
		FacesContext.getCurrentInstance().addMessage(null, message);
	}
}