package org.sagebionetworks.web.client.widget.table;

import org.gwtbootstrap3.client.ui.Anchor;
import org.gwtbootstrap3.client.ui.Heading;
import org.gwtbootstrap3.client.ui.Icon;
import org.gwtbootstrap3.client.ui.LinkedGroupItemText;
import org.gwtbootstrap3.client.ui.ListGroupItem;
import org.gwtbootstrap3.client.ui.constants.HeadingSize;
import org.gwtbootstrap3.client.ui.constants.IconType;
import org.gwtbootstrap3.client.ui.constants.Pull;
import org.gwtbootstrap3.client.ui.html.Br;
import org.gwtbootstrap3.client.ui.html.ClearFix;
import org.gwtbootstrap3.client.ui.html.Div;
import org.gwtbootstrap3.client.ui.html.Span;
import org.gwtbootstrap3.client.ui.html.Text;
import org.sagebionetworks.repo.model.EntityHeader;
import org.sagebionetworks.repo.model.entity.query.EntityQueryResult;
import org.sagebionetworks.web.client.EntityTypeUtils;
import org.sagebionetworks.web.client.widget.user.UserBadge;

import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.i18n.client.DateTimeFormat.PredefinedFormat;

/**
 * Simple list item for an entity.
 * 
 * @author jmhill
 *
 */
public class TableEntityListGroupItem extends ListGroupItem {

	private static final String CREATED_ON = "Created on ";
	private static final String MODIFIED_ON = "Modified on ";
	private static final String BY = " by ";

	static final DateTimeFormat DATE_FORMAT = DateTimeFormat.getFormat(PredefinedFormat.DATE_TIME_SHORT);
	
	TableEntityListGroupItem(HeadingSize size, EntityHeader header, ClickHandler clickHandler){
		addStyleName("padding-10");
		Heading iconHeading = new Heading(HeadingSize.H3);
		iconHeading.setPull(Pull.LEFT);
		Icon icon = new Icon(EntityTypeUtils.getIconTypeForEntityClassName(header.getType()));
		icon.addStyleName("lightGreyText margin-right-10 moveup-10");
		iconHeading.add(icon);
		
		Heading heading = new Heading(size);
		Anchor anchor = new Anchor();
		anchor.setText(header.getName());
		anchor.addClickHandler(clickHandler);
		heading.add(anchor);
		heading.addStyleName("displayInline");
		
//		LinkedGroupItemText createdOnDiv = new LinkedGroupItemText();
//		createdOnDiv.add(new Text(CREATED_ON+DATE_FORMAT.format(header.getCreatedOn())));
//		Span hiddenOnXs = new Span();
//		hiddenOnXs.addStyleName("hidden-xs");
//		createdOnDiv.add(hiddenOnXs);
//		hiddenOnXs.add(new Text(BY));
//		hiddenOnXs.add(createdByUserBadge);
//		createdByUserBadge.asWidget().addStyleName("movedown-9 margin-right-10");
		
		// Uncomment when PLFM-3054/PLFM-4220 have been fixed.
//		hiddenOnXs.add(new Text(MODIFIED_ON+DATE_FORMAT.format(header.getModifiedOn())+BY));
//		hiddenOnXs.add(modifiedByUserBadge);
//		modifiedByUserBadge.asWidget().addStyleName("movedown-9");
		
		anchor = new Anchor("#!Synapse:"+header.getId());
		anchor.setTarget("_blank");
		anchor.setIcon(IconType.EXTERNAL_LINK);
		anchor.addStyleName("margin-left-10 moveup-2");
		
		Div div = new Div();
		div.add(new ClearFix());
		div.add(iconHeading);
		div.add(heading);
		div.add(anchor);
//		div.add(createdOnDiv);
		this.add(div); 
	}
	
}

@@ -179,64 +179,8 @@
 on;%0A
-import org.gwtbootstrap3.client.ui.LinkedGroupItemText;%0A
 impo
@@ -393,52 +393,8 @@
 ll;%0A
-import org.gwtbootstrap3.client.ui.html.Br;%0A
 impo
@@ -499,209 +499,47 @@
 org.
-gwtbootstrap3.client.ui.html.Span;%0Aimport org.gwtbootstrap3.client.ui.html.Text;%0Aimport org.sagebionetworks.repo.model.EntityHeader;%0Aimport org.sagebionetworks.repo.model.entity.query.EntityQueryResult
+sagebionetworks.repo.model.EntityHeader
 ;%0Aim
@@ -595,69 +595,59 @@
 ls;%0A
+%0A
 import 
-org.sagebionetworks.web.client.widget.user.UserBadge;%0A
+com.google.gwt.event.dom.client.ClickEvent;
 %0Aimp
@@ -812,16 +812,62 @@
 dFormat;
+%0Aimport com.google.gwt.user.client.ui.TextBox;
 %0A%0A/**%0A *
@@ -2530,16 +2530,409 @@
 9%22);%0A%09%09%0A
+%09%09final TextBox synIdTextBox = new TextBox();%0A%09%09synIdTextBox.addStyleName(%22hidden-xs right border-none noBackground margin-right-15%22);%0A%09%09synIdTextBox.setReadOnly(true);%0A%09%09synIdTextBox.setWidth(%22130px%22);%0A%09%09synIdTextBox.setValue(header.getId());%0A%09%09synIdTextBox.addClickHandler(new ClickHandler() %7B%0A%09%09%09@Override%0A%09%09%09public void onClick(ClickEvent event) %7B%0A%09%09%09%09synIdTextBox.selectAll();%0A%09%09%09%7D%0A%09%09%7D);%0A
 %09%09anchor
@@ -3213,16 +3213,41 @@
 nchor);%0A
+%09%09div.add(synIdTextBox);%0A
 //%09%09div.

add synapse id to table/view list item