package eu.dnetlib.client.shared;

import com.sencha.gxt.widget.core.client.Dialog.PredefinedButton;
import com.sencha.gxt.widget.core.client.box.MessageBox;

import eu.dnetlib.client.managers.ActiveComponentsManager;

public class Warnings {

	private StartUpComponents startUpComponents=new StartUpComponents();
	private ActiveComponentsManager activeManager;
	
	public boolean  isLockedComponentAndMessage(String id){
		if (activeManager.isLocked(id, startUpComponents.getUser().getId())) {
			final MessageBox box = warningLockedComponents();
			box.show();
			return true;
		}
		return false;
	}
	public boolean  isPublishedComponentAndMessage(String id){
		if(Filtering.filterPublished(id, startUpComponents)){
			final MessageBox box = warningDeletePublished();
			box.show();
			return true;
		}
		return false;
	}
	public void deleteAction(String id){
		if (isLockedComponentAndMessage(id)) {
			return;

		} else {
			if(!isPublishedComponentAndMessage(id)){
//				deleteCB(id).show();
//				TODO
			}
		}
	}
	// warning box for components in use
	public MessageBox warningLockedComponents() {
		final MessageBox warning = new MessageBox(" Warning", "Current Componenent is in use by another user- edit disabled.");

		warning.setPredefinedButtons(PredefinedButton.OK);
		warning.setIcon(MessageBox.ICONS.warning());
		warning.setMinHeight(150);

		return warning;
	}
	public static  MessageBox warningDeletePublished() {
		final MessageBox warning = new MessageBox(" Warning", "This component is published.");

		warning.setPredefinedButtons(PredefinedButton.OK);
		warning.setIcon(MessageBox.ICONS.error());
		warning.setMinHeight(150);

		return warning;
	}
}
