import "../../../../../../../node_modules/.pnpm/vue@3.3.4/node_modules/vue/dist/vue.runtime.esm-bundler.mjs";
import { FileTypeEnum } from "../../../../../../enums/fileTypeEnum.mjs";
import { JSONParse, JSONStringify } from "../../../../../../utils/utils.mjs";
import "../../../../../../../node_modules/.pnpm/crypto-js@4.1.1/node_modules/crypto-js/index.mjs";
import "../../../../../../enums/pageEnum.mjs";
import "../../../../../../router/index.mjs";
import "../../../../../../store/modules/designStore/designStore.mjs";
import "../../../../../../../node_modules/.pnpm/vue3-lazyload@0.2.5-beta_a6dezdz3je235ci4e3tu4rayna/node_modules/vue3-lazyload/dist/vue3-lazyload.esm.mjs";
import "../../../../../../components/GoSkeleton/index.vue.mjs";
import "../../../../../../components/GoLoading/index.mjs";
import "../../../../../../settings/designSetting.mjs";
import { readFile, downloadTextFile } from "../../../../../../utils/file.mjs";
import { ref } from "../../../../../../../node_modules/.pnpm/@vue_reactivity@3.3.4/node_modules/@vue/reactivity/dist/reactivity.esm-bundler.mjs";
import { nextTick } from "../../../../../../../node_modules/.pnpm/@vue_runtime-core@3.3.4/node_modules/@vue/runtime-core/dist/runtime-core.esm-bundler.mjs";
const useFile = (targetData) => {
  const uploadFileListRef = ref();
  const beforeUpload = ({ file }) => {
    uploadFileListRef.value = [];
    const type = file.file.type;
    if (type !== FileTypeEnum.JSON && type !== FileTypeEnum.TXT) {
      window["$message"].warning("仅支持上传 【JSON】 格式文件，请重新上传！");
      return false;
    }
    return true;
  };
  const customRequest = (options) => {
    const { file } = options;
    nextTick(() => {
      if (file.file) {
        readFile(file.file).then((fileData) => {
          targetData.value.option.dataset = JSONParse(fileData);
        });
      } else {
        window["$message"].error("导入数据失败，请稍后重试或联系管理员！");
      }
    });
  };
  const download = () => {
    try {
      window["$message"].success("下载中，请耐心等待...");
      downloadTextFile(JSONStringify(targetData.value.option.dataset), void 0, "json");
    } catch (error) {
      window["$message"].error("下载失败，数据错误！");
    }
  };
  return {
    uploadFileListRef,
    beforeUpload,
    customRequest,
    download
  };
};
export {
  useFile
};
