'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var vue = require('vue');
var shared = require('@vue/shared');
var index = require('../../upload/index.js');
require('../../upload/src/upload-list.js');
var uploadList_vue_vue_type_script_lang = require('../../upload/src/upload-list.vue_vue_type_script_lang.js');

var script = vue.defineComponent({
  name: "ElUploadV2",
  components: {
    ElUpload: index.ElUpload,
    ElUploadList: uploadList_vue_vue_type_script_lang["default"]
  },
  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: () => shared.NOOP
    }
  },
  emits: ["update:value"],
  setup(props, { emit }) {
    const fileList = vue.ref([]);
    const isSingleUpload = vue.computed(() => {
      return props.type === "single";
    });
    vue.watch(() => props.value, (value) => {
      if (props.type === "single") {
        fileList.value = [];
      } else {
        fileList.value = value;
      }
    });
    const fileUrlList = vue.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
    };
  }
});

exports["default"] = script;
//# sourceMappingURL=index.vue_vue_type_script_lang.js.map
