import { ref } from 'vue';
import { uuid } from '../../../utils/uuid.mjs';

"use strict";
const useImage = (props) => {
  const uploadVisible = ref(false);
  const allowWatch = true;
  const fileList = ref([]);
  let oldInputValue = "";
  let controller = new AbortController();
  const importData = async (inputValue) => {
    fileList.value.length = 0;
    const imgs = inputValue.split(",");
    if (inputValue) {
      let res;
      oldInputValue = inputValue;
      console.log(oldInputValue, inputValue);
      if (oldInputValue && oldInputValue == inputValue) {
        controller.abort();
        console.log("\u53D6\u6D88\u8BF7\u6C42==========>");
        controller = new AbortController();
      }
      try {
        res = await props.imgUrlRequest?.({ id: inputValue, options: { signal: controller.signal } });
      } catch (error) {
        console.log(error);
      }
      if (res?.data) {
        imgs.forEach((imgId) => {
          res.data.forEach((item) => {
            if (item.id == imgId) {
              let node = {
                domuuid: uuid(),
                module: ""
              };
              node.module = props.module || "";
              Object.assign(node, item);
              fileList.value.push(node);
            }
          });
        });
      }
    }
  };
  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;
  };
  const openUpload = () => {
    uploadVisible.value = true;
  };
  const closeUpload = () => {
    uploadVisible.value = false;
  };
  return { uploadVisible, fileList, getValue, importData, allowWatch, openUpload, closeUpload };
};

export { useImage };
//# sourceMappingURL=useImage.mjs.map
