package tars.ui;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import javafx.fxml.FXML;
import javafx.scene.Node;
import javafx.scene.control.Label;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;
import tars.commons.util.FxViewUtil;

/**
 * A ui for the information panel that is at the header of the application
 */
public class InformationHeader extends UiPart {
    public static final String INFORMATION_HEADER_ID = "informationHeader";
    private static final String INFO_HEADER_STYLE_SHEET = "info-header";
    private static final String FXML = "InformationHeader.fxml";
    private static DateFormat df = new SimpleDateFormat("E d, MMM");

    private AnchorPane placeHolder;

    private AnchorPane mainPane;

    @FXML
    private HBox header;
    @FXML
    private Label date;
    @FXML
    private Label numUpcoming;
    @FXML
    private Label numOverdue;


    public static InformationHeader load(Stage primaryStage, AnchorPane placeHolder) {
        InformationHeader infoHeader = UiPartLoader.loadUiPart(primaryStage, placeHolder, new InformationHeader());
        infoHeader.configure();
        return infoHeader;
    }

    public void configure() {
        header.getStyleClass().add(INFO_HEADER_STYLE_SHEET);
        Date today = new Date();
        date.setText(df.format(today));
        numUpcoming.setText("0");
        numOverdue.setText("0");

        FxViewUtil.applyAnchorBoundaryParameters(header, 0.0, 0.0, 0.0, 0.0);
        FxViewUtil.applyAnchorBoundaryParameters(mainPane, 0.0, 0.0, 0.0, 0.0);
        placeHolder.getChildren().add(mainPane);
    }

    @Override
    public void setNode(Node node) {
        mainPane = (AnchorPane) node;
    }

    @Override
    public void setPlaceholder(AnchorPane placeholder) {
        this.placeHolder = placeholder;
    }

    @Override
    public String getFxmlPath() {
        return FXML;
    }

}

@@ -98,16 +98,137 @@
 l.Date;%0A
+import java.util.logging.Logger;%0A%0Aimport com.google.common.eventbus.Subscribe;%0A%0Aimport javafx.collections.ObservableList;
 %0Aimport 
@@ -349,45 +349,8 @@
 ne;%0A
-import javafx.scene.layout.GridPane;%0A
 impo
@@ -429,23 +429,187 @@
 ons.
-util.FxViewUtil
+core.LogsCenter;%0Aimport tars.commons.events.model.TarsChangedEvent;%0Aimport tars.commons.util.DateTimeUtil;%0Aimport tars.commons.util.FxViewUtil;%0Aimport tars.model.task.ReadOnlyTask
 ;%0A%0A/
@@ -616,17 +616,17 @@
 **%0A * A 
-u
+U
 i for th
@@ -643,29 +643,8 @@
 ion 
-panel that is at the 
 head
@@ -717,16 +717,102 @@
 iPart %7B%0A
+    private static final Logger logger = LogsCenter.getLogger(StatusBarFooter.class);%0A
     publ
@@ -1036,16 +1036,22 @@
  static 
+final 
 DateForm
@@ -1091,16 +1091,133 @@
 , MMM%22);
+%0A    private static final String STATUS_UNDONE = %22Undone%22;%0A    %0A    private static ObservableList%3CReadOnlyTask%3E list;
 %0A%0A    pr
@@ -1246,17 +1246,16 @@
 Holder;%0A
-%0A
     priv
@@ -1511,24 +1511,76 @@
  placeHolder
+%0A            , ObservableList%3CReadOnlyTask%3E taskList
 ) %7B%0A        
@@ -1683,24 +1683,49 @@
 nHeader());%0A
+        list = taskList;%0A
         info
@@ -1881,104 +1881,39 @@
     
-Date today = new Date();%0A        date.setText(df.format(today));%0A        numUpcoming.setText(%220%22
+setDate();%0A        setUpcoming(
 );%0A 
@@ -1923,30 +1923,19 @@
     
-num
+set
 Overdue
-.setText(%220%22
+(
 );%0A%0A
@@ -2141,16 +2141,1102 @@
 nPane);%0A
+        registerAsAnEventHandler(this);%0A    %7D%0A%0A    private void setDate() %7B%0A        Date today = new Date();%0A        date.setText(df.format(today));        %0A    %7D%0A    %0A    private void setUpcoming() %7B%0A        int count = 0;%0A        for (ReadOnlyTask t : list) %7B%0A            if (DateTimeUtil.isWithinWeek(t.getDateTime().getEndDate())%0A                    && t.getStatus().toString().equals(STATUS_UNDONE)) %7B%0A                count++;%0A            %7D%0A        %7D%0A        numUpcoming.setText(String.valueOf(count));%0A    %7D%0A    %0A    private void setOverdue() %7B%0A        int count = 0;%0A        for (ReadOnlyTask t : list) %7B%0A            if (DateTimeUtil.isOverDue(t.getDateTime().getEndDate())%0A                    && t.getStatus().toString().equals(STATUS_UNDONE)) %7B%0A                count++;%0A            %7D%0A        %7D%0A        numOverdue.setText(String.valueOf(count));%0A    %7D%0A    %0A    @Subscribe%0A    public void handleTarsChangedEvent(TarsChangedEvent event) %7B%0A        logger.info(LogsCenter.getEventHandlingLogMessage(event, %22Update information header%22));%0A        setUpcoming();%0A        setOverdue();%0A
     %7D%0A%0A 

Set upcoming and overdue tasks