import { useMain as useDataImportMain } from '@/views/dataManage/index/hooks/dataImport.ts'
import { ref } from 'vue'

export const useMain = () => {

  const { listRequest, importRequest, deleteRequest, updateRequest } = useDataImportMain()

  const importData = ref([])

  // 获取导入数据
  const getImportData = async () => {
    const res = await listRequest.request()
    console.log('res', res)
    if (res?.code == 200) {
      importData.value = res.data
    }
    return res
  }

  // 导入数据
  const onImportData = async (data: Record<string, any>) => {
    const res = await importRequest.request(data)
    console.log('res', res)
    return res
  }

  // 删除
  const onDelete = async (data: Record<string, any>) => {
    const res = await deleteRequest.request(data)
    console.log('res', res)
    return res
  }

  // 更新
  const onUpdate = async (data: Record<string, any>) => {
    const res = await updateRequest.request(data)
    console.log('res', res)
    return res
  }

  const state = {
    importData: importData
  }

  return {
    state,
    api: {
      getImportData,
      onDelete,
      onImportData,
      onUpdate
    },
    requestMap: {
      listRequest,
      importRequest,
      deleteRequest
    }
  }
}
