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 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) {
        //task
        if (entry.getStartTime().toString().contains("empty") 
        		&& entry.getEndTime().toString().contains("empty")) {
            startTime.setVisible(false);
            endTime.setVisible(false);
        } 
        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) {
        
        if (entry.tagsString().contains("Completed")) {
            cardPane.setStyle(COMPLETED_INDICATION);   // if entry completed
        } 
        //else if (entryRead.getDate().before(new Date())) {
            // if entry overdue
            //cardPane.setStyle(OVERDUE_INDICATION);
       // }
    }
}

@@ -629,24 +629,29 @@
 layedIndex;%0A
+    %0A
     //@@auth
@@ -845,32 +845,37 @@
 %0A    //@@author%0A
+    %0A
     public Entry
@@ -1410,24 +1410,25 @@
 (%22Start Time
+ 
 : %22 + entry.
@@ -1476,16 +1476,26 @@
 xt(%22Date
+          
 : %22 + en
@@ -1549,16 +1549,19 @@
 End Time
+   
 : %22 + en
@@ -1644,24 +1644,29 @@
  //@@author%0A
+    %0A
     public H
@@ -1984,16 +1984,25 @@
       //
+deadline 
 task%0A   
@@ -2208,32 +2208,56 @@
 se);%0A        %7D %0A
+        //floating task%0A
         if (entr
@@ -2634,20 +2634,34 @@
 ) %7B%0A    
-    
+%09//entry completed
 %0A       
@@ -2768,40 +2768,47 @@
 ;   
-// if entry completed%0A        %7D 
+%0A        %7D %0A        // if entry overdue
 %0A   
@@ -2870,39 +2870,8 @@
  %7B%0A 
-           // if entry overdue%0A
     
@@ -2918,16 +2918,18 @@
 CATION);
+  
 %0A       

update EntryCard.java