import { defineStore } from 'pinia';
import { ref, computed } from 'vue';
import client from "./client";
import icpList from "../../utils/ipc";

const clientStore = client();

export const configInfo = defineStore('config',()=>{
  //作废了
  const digiCamControlPath = ref("C:\\Program Files (x86)\\digiCamControl")
  const updateDigiCamControlPath = (data:string)=>{
    digiCamControlPath.value = data
  }

  const appConfig = ref({})


  const getAppConfig = async ()=>{
    return new Promise((resolve, reject) => {
      clientStore.ipc.send(icpList.utils.getAppConfig);
      clientStore.ipc.on(icpList.utils.getAppConfig, async (event, result) => {
        appConfig.value = result;
        resolve(appConfig.value)
      })
    })
  }


  clientStore.ipc.send(icpList.utils.getAppConfig);
  clientStore.ipc.on(icpList.utils.getAppConfig, async (event, result) => {
    appConfig.value = result;
  })


  //  1 为拍照并处理图像 2 为仅处理图像
  const appModel = ref(1)
  const updateAppModel = (data:number)=>{
    appModel.value = data
  }
  return {
    digiCamControlPath,
    updateDigiCamControlPath,
    appModel,
    updateAppModel,
    appConfig,
    getAppConfig,
  }
},{
  persist:true,
})


export default configInfo;
