package seedu.task.ui;

import javafx.fxml.FXML;
import javafx.scene.control.Label;
import javafx.scene.layout.FlowPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Region;
import seedu.task.model.task.ReadOnlyTask;

public class TaskCard extends UiPart<Region> {

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

    @FXML
    private HBox cardPane;
    @FXML
    private Label name;
    @FXML
    private Label id;
    @FXML
    private Label due;
    @FXML
    private Label duration_start;
    @FXML
    private Label duration_end;
    @FXML
    private FlowPane tags;
    @FXML
    private Label complete;

    public TaskCard(ReadOnlyTask task, int displayedIndex) {
        super(FXML);
        name.setText(task.getDescription().description);
        id.setText(Integer.toString(displayedIndex));
        updateDueLabel(task);
        updateDurationLabel(task);
        updateCompleteLabel(task);
        initTags(task);
    }

    private void initTags(ReadOnlyTask task) {
        task.getTags().forEach(tag -> tags.getChildren().add(new Label(tag.tagName)));
    }

    private void updateDueLabel(ReadOnlyTask task) {
        if (task.getDueDate() == null) {
            due.setVisible(false);
        } else {
            due.setVisible(true);
            due.setText(task.getDueDate().toString());
        }
    }

    private void updateDurationLabel(ReadOnlyTask task) {
        if (task.getDuration() == null) {
            duration_start.setVisible(false);
            duration_end.setVisible(false);
        } else {
            duration_start.setVisible(true);
            duration_end.setVisible(true);
            duration_start.setText(task.getDurationStart());
            duration_end.setText(task.getDurationEnd());
        }
    }

    private void updateCompleteLabel(ReadOnlyTask task) {
        complete.setText("✓");
    }
}

@@ -333,16 +333,67 @@
 d.fxml%22;
+%0A    private static final String EMPTY_STRING = %22%22;
 %0A%0A    @F
@@ -1901,28 +1901,152 @@
     
-complete.setText(%22%E2%9C%93%22
+if (task.getComplete() == null) %7B%0A            return;%0A        %7D%0A        complete.setText(task.getComplete().getCompletion() ? %22%E2%9C%93%22 : EMPTY_STRING
 );%0A 

complete task gui