import { useCtx } from "@/comm/ctx";
import ListModule from "..";
import { queenApi } from "queenjs";
export default ListModule.action({
  async getAssetList() {
    const { deviceCtrl } = useCtx();
    const appDataDir = deviceCtrl.appDataDir;
    const currentCategory = localStorage.getItem("category") || "default";
    const assetsJson = await deviceCtrl.ReadFileText(
      `${appDataDir}/screen/assets_${currentCategory}.json`
    );

    if (assetsJson.error) {
      const res = await deviceCtrl.WriteFileText(
        `${appDataDir}/screen/assets_${currentCategory}.json`,
        "[]"
      );
      this.store.list = [];
    }
    if (assetsJson.text) {
      const assets = JSON.parse(assetsJson.text);
      this.store.list = assets;
    }
  },
  async getAssetDetail(id: string) {
    const res = await this.https.getAssetDetail(id);
    if (res.errorNo != 200) {
      queenApi.messageError(res.errorDesc);
      return;
    }
    return res.result;
  },
});
