<template>
  <v-app class="tasksList">
    <v-card
      class="tasksView tasksListItem tasksViewList pt-6"
      flat>
      <v-item-group class="pa-4">
        <div class="ma-0 border-box-sizing">
          <div
            class="pt-0 pb-8 px-4 projectTaskItem">
            <tasks-view-list-column
              :status="statusList"
              :tasks-list="tasksList"
              @updateTaskCompleted="updateTaskCompleted"
              @updateTaskStatus="updateTaskStatus" />
          </div>
      </div></v-item-group>
    </v-card>
  </v-app>
</template>
<script>
import {updateTask} from '../../../taskDrawer/taskDrawerApi';
  export default {

    props: {
      statusList: {
        type: Array,
        default: () => []
      },
      tasksList: {
        type: Array,
        default: () => []
      }
    },
    data () {
      return {
        
        tasksStatsStartValue:0,
      }
    },
    mounted() {
      this.$root.$on('deleteTask', (event) => {
        if (event && event.detail) {
          this.tasksList = this.tasksList.filter((t) => t.id !== event.detail);
        }
      });
    },

    methods: {
      getTasksByStatus(items ,statusName) {
        const tasksByStatus = [];
        items.forEach((item) => {
          if(item.task) {
            if (item.task.status) {
              if (item.task.status.name === statusName) {
                tasksByStatus.push(item);
              }
            }
          }
        });
        return tasksByStatus;
      },
    updateTaskCompleted(e){
      if( !this.filterTaskCompleted ) {
        this.$root.$emit('update-task-completed', e);
      }
    },
       updateTaskStatus(task,newStatus){
              const status = this.statusList.find(s => s.name === newStatus);
              if(status){
               task.status = status;
               this.updateTask(task)
              } 
      },
      updateTask(task) {
        if(task.id!=null){
          updateTask(task.id,task);
/*           window.setTimeout(() => {
             this.$root.$emit('task-added', this.task)
          }, 200); */
        }
      },
    }
  }
</script>
