'use strict';

var vue = require('vue');
var uuid = require('../../../utils/uuid.js');

"use strict";
const useFile = (props) => {
  const uploadVisible = vue.ref(false);
  const allowWatch = true;
  const fileList = vue.ref([]);
  const importData = async (inputValue) => {
    fileList.value.length = 0;
    const imgs = inputValue.split(",");
    if (inputValue) {
      let res;
      res = await props.fileRequest?.({ id: inputValue });
      if (res.data) {
        imgs.forEach((imgId) => {
          res.data.forEach((item) => {
            if (item.id == imgId) {
              let node = {
                domuuid: uuid.uuid(),
                module: ""
              };
              node.module = props.module || "";
              Object.assign(node, item);
              fileList.value.push(node);
            }
          });
        });
      }
    }
  };
  const openUpload = () => {
    uploadVisible.value = true;
  };
  const closeUpload = () => {
    uploadVisible.value = false;
  };
  const getValue = () => {
    let value = "";
    for (let i = 0; i < fileList.value.length; i++) {
      if (i == 0) {
        value += fileList.value[i].id;
      } else {
        value += "," + fileList.value[i].id;
      }
    }
    return value;
  };
  return { uploadVisible, fileList, getValue, importData, allowWatch, openUpload, closeUpload };
};

exports.useFile = useFile;
//# sourceMappingURL=useFile.js.map
