import { defineComponent, ref, computed, watch } from 'vue';
import { NOOP } from '@vue/shared';
import { ElUpload } from '../../upload/index.mjs';
import '../../upload/src/upload-list.mjs';
import script$1 from '../../upload/src/upload-list.vue_vue_type_script_lang.mjs';

var script = defineComponent({
  name: "ElUploadV2",
  components: {
    ElUpload,
    ElUploadList: script$1
  },
  props: {
    value: {
      type: [Array, String],
      default: () => {
        return "";
      }
    },
    action: {
      type: String,
      default: "/v2/file/file/batchUploadImg"
    },
    headers: {
      type: Object,
      default: () => ({})
    },
    method: {
      type: String,
      default: "post"
    },
    data: {
      type: Object,
      default: () => ({
        token: localStorage.getItem("token")
      })
    },
    multiple: {
      type: Boolean,
      default: false
    },
    name: {
      type: String,
      default: "file"
    },
    drag: {
      type: Boolean,
      default: false
    },
    withCredentials: Boolean,
    showFileList: {
      type: Boolean,
      default: true
    },
    accept: {
      type: String,
      default: ""
    },
    type: {
      type: String,
      default: "select"
    },
    responseHandle: {
      type: Function,
      default: (file) => file.data.list[0].raw
    },
    autoUpload: {
      type: Boolean,
      default: true
    },
    listType: {
      type: String,
      default: "picture-card"
    },
    httpRequest: {
      type: Function
    },
    disabled: Boolean,
    limit: {
      type: Number,
      default: null
    },
    onExceed: {
      type: Function,
      default: () => NOOP
    }
  },
  emits: ["update:value"],
  setup(props, { emit }) {
    const fileList = ref([]);
    const isSingleUpload = computed(() => {
      return props.type === "single";
    });
    watch(() => props.value, (value) => {
      if (props.type === "single") {
        fileList.value = [];
      } else {
        fileList.value = value;
      }
    });
    const fileUrlList = computed(() => {
      if (isSingleUpload.value) {
        return [props.value];
      } else {
        return props.value.map((e) => ({
          url: e
        }));
      }
    });
    const getEmitValue = (fileList2) => {
      if (isSingleUpload.value) {
        return fileList2[0];
      } else {
        return fileList2;
      }
    };
    const onSuccess = (res) => {
      emit("update:value", isSingleUpload.value ? res : props.value.concat([res]));
    };
    const onRemove = (file, fileList2) => {
      if (!fileList2) {
        emit("update:value", isSingleUpload.value ? "" : []);
        return;
      }
      emit("update:value", getEmitValue(fileList2.map((e) => e.url)));
    };
    const onChange = (file, fileList2) => {
      const list = (isSingleUpload.value ? [file] : fileList2).map((e) => {
        if (e.response) {
          if (props.responseHandle) {
            return props.responseHandle(e.response);
          }
          return e.response;
        } else {
          return e.url;
        }
      });
      emit("update:value", getEmitValue(list));
    };
    const getFileList = (file) => {
      return [{ url: file }];
    };
    return {
      uploadProps: props,
      fileUrlList,
      onSuccess,
      onRemove,
      onChange,
      isSingleUpload,
      getFileList
    };
  }
});

export { script as default };
//# sourceMappingURL=index.vue_vue_type_script_lang.mjs.map
