import { observable, action, computed } from 'mobx';

export default class Task {
    @observable data = [];
    @observable isLoading = false;
    @observable isSearching = false;
    @observable taskId = '';
    @observable filterBy = 'all';
    @observable selectedData = {};
    // @observable taskData = {};

    constructor(context) {
        this.http = context.http;
        this.context = context;
    }
    @action
    changeFilterBy(v){
      this.filterBy = v;
    }
    @action
    getAll() {
      this.isLoading = true;
      return this.http.get("tasks")
        .then(res => {
          this.data = res.data;
          this.isLoading = false;
        })
        .catch(err => {
          this.isLoading = false;
          throw err;
        })
    }

    @action
    getDetail(id) {
      this.isLoading = true;
      return this.http.get("tasks/"+id)
        .then(res => {
          this.selectedData = res;
          this.isLoading = false;
        })
        .catch(err => {
          this.isLoading = false;
          throw err;
        })
    }

    @computed 
	  get isEmpty(){
		if(this.tasks.length > 0){
			return false;
		}
		return true;
	}

}
