/** @@author A0142130A **/
package seedu.taskell.ui;

import java.time.LocalDateTime;
import java.util.ArrayList;

import jfxtras.scene.control.agenda.Agenda;
import jfxtras.scene.control.agenda.Agenda.Appointment;
import seedu.taskell.model.Model;
import seedu.taskell.model.ReadOnlyTaskManager;
import seedu.taskell.model.TaskManager;
import seedu.taskell.model.task.ReadOnlyTask;
import seedu.taskell.model.task.UniqueTaskList;

/** This class holds the necessary elements to display calendar UI via Agenda API from jfxtras
 * */

public class CalendarView {
    
    private static Model model;
    
    private Agenda agenda;
    
    public CalendarView() {
        agenda = new Agenda();
        setAgendaProperties();
        loadTasks();
    }
    
    public static void setData(Model m) {
        model = m;
    }
    
    public Agenda getAgenda() {
        return agenda;
    }
    
    private void setAgendaProperties() {
        agenda.setAllowDragging(false);
        agenda.setAllowResize(false);
        agenda.setFocusTraversable(false);
        
        agenda.setStyle("-fx-font-size: 12pt");
    }
    
    public void loadTasks() {
        ReadOnlyTaskManager taskManager = model.getTaskManager();
        UniqueTaskList taskList = taskManager.getUniqueTaskList();
        
        ArrayList<Appointment> appointments = new ArrayList<>();
        int i=0;
        
        for (ReadOnlyTask task: taskList) {
            appointments.add(new Agenda.AppointmentImplLocal()
                    .withStartLocalDateTime(LocalDateTime.now().plusDays(i))
                    .withEndLocalDateTime(LocalDateTime.now().plusDays(i).plusHours(4).plusMinutes(30))
                    .withSummary(task.getDescription().description)
                    .withAppointmentGroup(
                            new Agenda.AppointmentGroupImpl().withStyleClass("group"+i)));
            i++;
        }
        
        
        
        

        agenda.appointments().addAll(appointments);
        
        //"-fx-background-color: #EC407A; -fx-fill: #EC407A;"
    }

}

@@ -317,27 +317,33 @@
 l.model.
-TaskManager
+task.ReadOnlyTask
 ;%0Aimport
@@ -364,36 +364,72 @@
 .model.task.
-ReadOnlyTask
+Task;%0Aimport seedu.taskell.model.task.TaskStatus
 ;%0Aimport see
@@ -893,24 +893,84 @@
 tAgenda() %7B%0A
+        agenda.appointments().clear();%0A        loadTasks();%0A
         retu
@@ -1145,32 +1145,69 @@
 ersable(false);%0A
+        //agenda.setOnScroll(value);%0A
         %0A       
@@ -1509,17 +1509,17 @@
   int i=
-0
+1
 ;%0A      
@@ -1577,16 +1577,75 @@
         
+%0A            if (isValidEventTask(task)) %7B%0A                
 appointm
@@ -1703,24 +1703,28 @@
             
+    
 .withStartLo
@@ -1739,145 +1739,170 @@
 ime(
-LocalDateTime.now().plusDays(i))%0A                    .withEndLocalDateTime(LocalDateTime.now().plusDays(i).plusHours(4).plusMinutes(30))%0A
+task.getStartDate().toLocalDateTime(task.getStartTime()))%0A                        .withEndLocalDateTime(task.getEndDate().toLocalDateTime(task.getEndTime()))%0A    
     
@@ -1981,24 +1981,28 @@
             
+    
 .withAppoint
@@ -2040,16 +2040,20 @@
         
+    
 new Agen
@@ -2123,23 +2123,14 @@
     
-i++;%0A        %7D%0A
+%7D%0A    
     
@@ -2134,32 +2134,40 @@
        %0A        
+    i++;
 %0A        %0A      
@@ -2151,32 +2151,33 @@
    i++;%0A        
+%7D
 %0A        %0A%0A     
@@ -2170,17 +2170,16 @@
        %0A
-%0A
         
@@ -2300,10 +2300,216 @@
 %0A    %7D%0A%0A
+    private boolean isValidEventTask(ReadOnlyTask task) %7B%0A        return task.getTaskStatus().toString().equals(TaskStatus.INCOMPLETE) %0A                && task.getTaskType().equals(Task.EVENT_TASK);%0A    %7D%0A%0A
 %7D%0A

edit calendar view, add task views