import { StateColor } from "../constants"
import { ValuesBucket } from "@kit.ArkData"

export interface ITaskItem extends ValuesBucket{
  id: number | null
  taskName: string //任务名称
  detail: string  //详细内容
  startDate: number  //开始时间
  dueDate: number  //截止时间
  isCompleted: number //是否已完成
  // progressValue: number  //
  category: number  //分类
  categoryName:string
  topped: number  //置顶
}
@ObservedV2
export class TaskItem{
  id: number|null
  @Trace
  taskName: string //任务名称
  @Trace
  detail: string  //详细内容
  startDate: number  //开始时间
  @Trace
  dueDate: number  //截止时间
  @Trace
  isCompleted: number//是否已完成
  // @Trace
  progressValue: number=0  //
  @Trace
  category: number  //分类
  @Trace
  categoryName:string
  @Trace
  topped:number //置顶
  constructor(task:ITaskItem) {
    this.id=task.id as number
    this.taskName=task.taskName
    this.detail=task.detail
    this.startDate=task.startDate
    this.dueDate=task.dueDate
    this.isCompleted=task.isCompleted
    this.categoryName=task.categoryName
    // this.progressValue=task.progressValue
    this.category=task.category
    this.topped=task.topped
  }


  // getTaskProgress(){
  //   return this.progressValue
  // }

  getTaskState(){
    //获取总时间
    const fullTime=this.dueDate-this.startDate
    //当前时间
    const nowTime=new Date().getTime()
    //已经过去的时间
    const time=nowTime-this.startDate
    const progress=Math.floor(time/fullTime*10)
    this.progressValue=progress
    if(progress<2){
      return 'EASY'
      // return StateColor.EASY
    }else if(progress <4){
      return 'MILD'
      // this.progressValue=4
    }else if(progress <6){
      // this.progressValue=6
      return 'MEDIUM'
    }else if(progress<8){
      // this.progressValue=8
      return 'HARD'
    }else{
      // this.progressValue=10
      return 'CRITICAL'
    }
  }

  getTaskColor(){
    if(this.getTaskState()=='EASY'){
      return StateColor.EASY
    }else if(this.getTaskState()=='MILD'){
      return StateColor.MILD
    }else if(this.getTaskState()=='MEDIUM'){
      return StateColor.MEDIUM
    }else if(this.getTaskState()=='HARD'){
      return StateColor.HARD
    }else {
      return StateColor.CRITICAL
    }
  }
  getProgressPercent(){
    if(this.getTaskState()=='EASY'){
      return 15
    }else if(this.getTaskState()=='MILD'){
      return 35
    }else if(this.getTaskState()=='MEDIUM'){
      return 55
    }else if(this.getTaskState()=='HARD'){
      return 75
    }else {
      return 95
    }

  }
}

// new TaskItem({
//   id:1,
//   taskName:"猪猪",
//   detail:"haha",
//   startDate:new Date().getTime()-2592000000,
//   dueDate:new Date().getTime()+2592000000,
//   isCompleted:false,
//   category:1,
//   categoryName:"默认清单",
//   topped:false
// }),
// new TaskItem({
//   id:2,
//   taskName:"猪猪1",
//   detail:"haha1",
//   startDate:new Date().getTime(),
//   dueDate:new Date().getTime()+2592000000,
//   isCompleted:false,
//   category:1,
//   categoryName:"默认清单",
//   topped:false
// }),
// new TaskItem({
//   id:3,
//   taskName:"猪猪1",
//   detail:"ha2ha",
//   startDate:new Date().getTime(),
//   dueDate:new Date().getTime()+36000,
//   isCompleted:false,
//   categoryName:"默认清单",
//   category:1,
//   topped:false
// }),
