import { defineStore } from 'pinia'
import { reactive } from 'vue'
import { queryProjectState } from '@/api/project'
import { getFileType } from '@/api/file'
export const editorData = defineStore('counter', () => {
  // 定义数据(state)
  const stateList = reactive([])
  const typeList = reactive([])
  // 定义修改数据的方法 (action 同步+异步)
  const getStateList = () => {
    queryProjectState().then(res => {
      if (res.code === 0) {
        stateList.length = 0
        stateList.push(...res.data)
      }
    })
  }
  const getTypeList = () => {
    getFileType().then(res => {
      if (res.code === 0) {
        typeList.length = 0
        typeList.push(...res.data)
      }
    })
  }
  // 以对象的方式return供组件使用
  return {
    stateList,
    typeList,
    getStateList,
    getTypeList
  }
})
