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