package eu.dnetlib.client.resources;

import java.util.LinkedHashMap;

import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.HTML;

import eu.dnetlib.client.shared.Filtering;
import eu.dnetlib.client.shared.ResourceThumb;
import eu.dnetlib.client.shared.StartUpComponents;

public class Tab {
	protected FlowPanel panel = new FlowPanel();
	protected Filtering filter = null;
	protected ComponentsList componentsListTop = null;
	protected ComponentsList componentsListBottom = null;
	protected Button createButton;
	protected FlowPanel tabText = new FlowPanel();
	protected final LinkedHashMap<String, ResourceThumb> resourceThumbMap = new LinkedHashMap<String, ResourceThumb>();

	public Tab(String type, String topTitle, String topId, String bottomTitle, String bottomId, StartUpComponents startUpComponents) {
		createButton = new Button("Create");
		createButton.setStyleName("btn btn-info createButton");
		componentsListTop = new ComponentsList(topTitle, topId);
		tabText.setStyleName(" tabText " + type.toLowerCase().substring(0, 5) + "TabText");
		tabText.add(new HTML(type));
 		if (bottomTitle != null && bottomId != null) {
			componentsListBottom = new ComponentsList(bottomTitle, bottomId);
 		}
	}

	public void fillPanel() {
		panel.add(filter);
		panel.add(createButton);
		panel.add(componentsListTop.getVerticalPanel());
		filter.setMessageUp(componentsListTop.getFilteringNoResultsMessage());
		if (componentsListBottom != null) {
			filter.setMessageBottom(componentsListBottom.getFilteringNoResultsMessage());
			panel.add(componentsListBottom.getVerticalPanel());
		}
	}

	public Tab(String type, String id) {
		componentsListTop = new ComponentsList();
		panel.add(componentsListTop.getVerticalPanel());
		tabText.setStyleName(" tabText " + id + "TabText");
		tabText.add(new HTML(type));
	}

	public void setPanelsNumber(int top, int bottom) {
		filter.setMineCount(top);
		componentsListTop.setTitleNumber(top);
		if (componentsListBottom != null) {
			filter.setAllCount(bottom);
			componentsListBottom.setTitleNumber(bottom);
		}
	}

	public FlowPanel getPanel() {
		return panel;
	}

	public ComponentsList getComponentsListTop() {
		return componentsListTop;
	}

	public ComponentsList getComponentsListBottom() {
		return componentsListBottom;
	}

	public LinkedHashMap<String, ResourceThumb> getResourceThumbMap() {
		return resourceThumbMap;
	}

	public Filtering getFilter() {
		return filter;
	}

	public Button getCreateButton() {
		return createButton;
	}

	public FlowPanel getTabText() {
		return tabText;
	}

}
