package seedu.scheduler.ui;

//import java.util.Date;

import javafx.fxml.FXML;
import javafx.scene.Node;
import javafx.scene.control.Label;
import javafx.scene.layout.HBox;
import seedu.scheduler.model.entry.ReadOnlyEntry;

public class EntryCard extends UiPart{

    private static final String FXML = "EntryListCard.fxml";

    @FXML
    private HBox cardPane;
    @FXML
    private Label name;
    @FXML
    private Label id;
    @FXML
    private Label startTime;
    @FXML
    private Label date;
    @FXML
    private Label endDate;
    @FXML
    private Label endTime;
    @FXML
    private Label tags;

    private ReadOnlyEntry entry;
    private int displayedIndex;
    
    //@@author A0139956L
    public static final String COMPLETED_INDICATION = "-fx-background-color: #ccffcc;";
    public static final String OVERDUE_INDICATION = "-fx-background-color:  #ffcce6;";
    //@@author
    
    public EntryCard(){

    }

    public static EntryCard load(ReadOnlyEntry entry, int displayedIndex){
        EntryCard card = new EntryCard();
        card.entry = entry;
        card.displayedIndex = displayedIndex;
        return UiPartLoader.loadUiPart(card);
    }

    //@@author A0139956L
    @FXML
    public void initialize() {
        name.setText(entry.getName().fullName);
        hideFieldsAccordingToType(entry);
        indicatingColourByCondition(entry);
        id.setText(displayedIndex + ". ");
        startTime.setText("Start Time : " + entry.getStartTime().value);
        date.setText("Date          : " + entry.getDate().value);
        endTime.setText("End Time   : " + entry.getEndTime().value);
        tags.setText(entry.tagsString());
    }
    //@@author
    
    public HBox getLayout() {
        return cardPane;
    }

    @Override
    public void setNode(Node node) {
        cardPane = (HBox)node;
    }

    @Override
    public String getFxmlPath() {
        return FXML;
    }
    
    //@@author A0139956L
    public void hideFieldsAccordingToType(ReadOnlyEntry entry) {
        //deadline task
        if (entry.getStartTime().toString().contains("empty") 
        		&& entry.getEndTime().toString().contains("empty")) {
            startTime.setVisible(false);
            endTime.setVisible(false);
        } 
        //floating task
        if (entry.getStartTime().toString().contains("empty") 
        		&& entry.getEndTime().toString().contains("empty")
        		&& entry.getDate().toString().contains("empty")) {
            startTime.setVisible(false);
            endTime.setVisible(false);
            date.setVisible(false);
        } 
    }
    
    public void indicatingColourByCondition(ReadOnlyEntry entry) {
    	//entry completed
        if (entry.tagsString().contains("Completed")) {
            cardPane.setStyle(COMPLETED_INDICATION);   
        } 
        // if entry overdue
        //else if (entryRead.getDate().before(new Date())) {
             //cardPane.setStyle(OVERDUE_INDICATION);  
       // }
    }
}

@@ -1414,16 +1414,79 @@
  %22. %22);%0A
+        date.setText(%22Start Date : %22 + entry.getDate().value);%0A
         
@@ -1550,33 +1550,36 @@
 value);%0A        
-d
+endD
 ate.setText(%22Dat
@@ -1579,22 +1579,18 @@
 xt(%22
+End 
 Date  
-        
 : %22 
@@ -1592,32 +1592,35 @@
  : %22 + entry.get
+End
 Date().value);%0A 
@@ -1653,17 +1653,16 @@
 d Time  
- 
 : %22 + en

add endDate to EntryCard.java