import { defineStore } from 'pinia'
import taskApi from '@/api/task'

export const taskStore = defineStore('taskJump', () => {
  const initStatus = {
    weekStatus: false,
    dailyStatus: false,
    parentStatus: false,
    archiveStatus: false,
    leadStatus: false,
    newbieStatus: false,
  }
  // 任务页面红点
  const status = ref(initStatus)

  const setStatus = async () => {
    setStatusData(await taskApi.getTaskRewardStatus())
  }

  function setStatusData(data: any) {
    status.value = { ...status.value, ...data }
  }

  // Getters
  const hasRedPoint = computed(() => {
    return (
      status.value.leadStatus ||
      status.value.dailyStatus ||
      status.value.parentStatus ||
      status.value.archiveStatus ||
      status.value.newbieStatus
    )
  })

  function $reset() {
    status.value = initStatus
  }

  return {
    // 状态
    status,

    // Actions
    setStatus,
    setStatusData,
    $reset,
    // Getters
    hasRedPoint,
  }
})
