package org.sagebionetworks.web.client.widget.entity.tabs;

import org.gwtbootstrap3.client.ui.Anchor;
import org.gwtbootstrap3.client.ui.ListItem;
import org.gwtbootstrap3.client.ui.TabPane;
import org.gwtbootstrap3.client.ui.html.Div;
import org.sagebionetworks.web.client.widget.HelpWidget;

import com.google.gwt.core.shared.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.InlineHTML;
import com.google.gwt.user.client.ui.Widget;
import com.google.inject.Inject;

public class TabViewImpl implements TabView {
	
	@UiField
	Anchor tabItem;
	@UiField
	TabPane tabPane;
	
	HelpWidget helpWidget;
	@UiField
	ListItem tabListItem;
	@UiField
	Div contentDiv;
	boolean isActive = false;
	public interface TabViewImplUiBinder extends UiBinder<Widget, TabViewImpl> {}
	Presenter presenter;
	Widget widget;
	
	@Inject
	public TabViewImpl(HelpWidget helpWidget) {
		//empty constructor, you can include this widget in the ui xml
		TabViewImplUiBinder binder = GWT.create(TabViewImplUiBinder.class);
		widget = binder.createAndBindUi(this);
		this.helpWidget = helpWidget;
		tabItem.addClickHandler(new ClickHandler() {
			@Override
			public void onClick(ClickEvent event) {
				presenter.onTabClicked();
			}
		});
	}
	
	@Override
	public void setPresenter(Presenter presenter) {
		this.presenter = presenter;
	}
	
	@Override
	public void configure(String tabTitle, Widget content, String helpMarkdown, String helpLink) {
		contentDiv.clear();
		contentDiv.add(content);
		helpWidget.setHelpMarkdown(helpMarkdown);
		helpWidget.setHref(helpLink);
		tabItem.clear();
		InlineHTML html = new InlineHTML(tabTitle);
		html.addStyleName("margin-right-5");
		tabItem.add(html);
		tabItem.add(helpWidget.asWidget());
	}
	
	@Override
	public Widget getTabListItem() {
		return tabListItem;
	}
	@Override
	public void setTabListItemVisible(boolean visible) {
		tabListItem.setVisible(visible);
	}
	
	@Override
	public TabPane getTabPane() {
		return tabPane;
	}
	
	@Override
	public void setActive(boolean isActive) {
		this.isActive = isActive;
		if (isActive) {
			tabListItem.addStyleName("active");	
		} else {
			tabListItem.removeStyleName("active");
		}
		
		tabPane.setVisible(isActive);
	}
	@Override
	public boolean isActive() {
		return isActive;
	}
}

@@ -230,16 +230,62 @@
 ml.Div;%0A
+import org.gwtbootstrap3.client.ui.html.Text;%0A
 import o
@@ -333,16 +333,16 @@
 Widget;%0A
-
 %0Aimport 
@@ -572,16 +572,108 @@
 iField;%0A
+import com.google.gwt.user.client.ui.FocusPanel;%0Aimport com.google.gwt.user.client.ui.HTML;%0A
 import c
@@ -1125,16 +1125,49 @@
 widget;%0A
+%09ClickHandler tabClickedHandler;%0A
 %09%0A%09@Inje
@@ -1431,29 +1431,25 @@
 %09tab
-Item.add
 Click
+ed
 Handler
-(
+ = 
 new 
@@ -1559,17 +1559,16 @@
 %09%09%09%7D%0A%09%09%7D
-)
 ;%0A%09%7D%0A%09%0A%09
@@ -1918,26 +1918,57 @@
 ;%0A%09%09
-InlineHTML html = 
+FocusPanel panel = new FocusPanel();%0A%09%09panel.add(
 new 
@@ -1991,15 +1991,61 @@
 tle)
+)
 ;%0A%09%09
-htm
+panel.addClickHandler(tabClickedHandler);%0A%09%09pane
 l.ad
@@ -2070,16 +2070,30 @@
 -right-5
+ displayInline
 %22);%0A%09%09ta
@@ -2102,19 +2102,20 @@
 tem.add(
-htm
+pane
 l);%0A%09%09ta

create the same tab structure as the profile dashboard.