package seedu.ezdo.ui;

import java.util.Date;
import java.util.logging.Logger;

import org.controlsfx.control.StatusBar;

import com.google.common.eventbus.Subscribe;

import javafx.fxml.FXML;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.Region;
import seedu.ezdo.commons.core.LogsCenter;
import seedu.ezdo.commons.events.model.EzDoChangedEvent;
import seedu.ezdo.commons.util.FxViewUtil;

/**
 * A ui for the status bar that is displayed at the footer of the application.
 */
public class StatusBarFooter extends UiPart<Region> {
    private static final Logger logger = LogsCenter.getLogger(StatusBarFooter.class);

    @FXML
    private StatusBar syncStatus;
    @FXML
    private StatusBar saveLocationStatus;

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

    public StatusBarFooter(AnchorPane placeHolder, String saveLocation) {
        super(FXML);
        addToPlaceholder(placeHolder);
        setSyncStatus("Not updated yet in this session");
        setSaveLocation("./" + saveLocation);
        registerAsAnEventHandler(this);
    }

    private void addToPlaceholder(AnchorPane placeHolder) {
        FxViewUtil.applyAnchorBoundaryParameters(getRoot(), 0.0, 0.0, 0.0, 0.0);
        placeHolder.getChildren().add(getRoot());
    }

    private void setSaveLocation(String location) {
        this.saveLocationStatus.setText(location);
    }

    private void setSyncStatus(String status) {
        this.syncStatus.setText(status);
    }

    @Subscribe
    public void handleEzDoChangedEvent(EzDoChangedEvent ezce) {
        String lastUpdated = (new Date()).toString();
        logger.info(LogsCenter.getEventHandlingLogMessage(ezce, "Setting last updated status to " + lastUpdated));
        setSyncStatus("Last Updated: " + lastUpdated);
    }
}

@@ -361,16 +361,84 @@
 dEvent;%0A
+import seedu.ezdo.commons.events.storage.EzDoDirectoryChangedEvent;%0A
 import s
@@ -472,16 +472,16 @@
 ewUtil;%0A
-
 %0A/**%0A * 
@@ -1082,15 +1082,8 @@
 ion(
-%22./%22 + 
 save
@@ -1788,24 +1788,24 @@
 tUpdated));%0A
-
         setS
@@ -1852,11 +1852,492 @@
 );%0A    %7D
+%0A%0A    @Subscribe%0A    public void handleEzDoDirectoryChangedEvent(EzDoDirectoryChangedEvent ezce) %7B%0A        String lastUpdated = (new Date()).toString();%0A        logger.info(LogsCenter.getEventHandlingLogMessage(ezce, %22Setting last updated status to %22 + lastUpdated));%0A        logger.info(LogsCenter.getEventHandlingLogMessage(ezce, %22Setting save location to %22 + ezce.getPath()));%0A        setSyncStatus(%22Last Updated: %22 + lastUpdated);%0A        setSaveLocation(ezce.getPath());%0A    %7D
 %0A%7D%0A

Add method for StatusBarFooter to update save location when user executes save command