import { defineStore } from 'pinia'
import { getInfoList } from '@/http/apis/home'
import { getTodoNums } from '@/http/apis/toDoCenter/todoList'
export const useCountStore = defineStore('countConfig', {
  state: () => {
    return {
      projectCount: 0,
      notAppendNum: 0,
      appendNum: 0,
      totalNum: 0,
      infoList: []
    }
  },
  getters: {},
  actions: {
    setCountStore (data) {
      return new Promise((resolve, reject) => {
        getInfoList({ readed: false })
          .then(res => {
            this.infoList = res.data.records
            // console.log('this.infoList', this.infoList)
            this.projectCount = res.data.total
            resolve(res.data)
          })
          .catch(err => {
            reject(err)
          })
      })
    },
    setTodoNumsStore () {
      return new Promise((resolve, reject) => {
        getTodoNums()
          .then(res => {
            this.notAppendNum = res.data?.notAppendNum || 0
            this.appendNum = res.data?.appendNum || 0
            this.totalNum = res.data?.totalNum || 0
            resolve(res.data)
          })
          .catch(err => {
            reject(err)
          })
      })
    }
  },
  persist: {
    storage: localStorage,
    paths: ['projectCount', 'infoList']
  }
})
