'use strict';

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

var vue = require('vue');
var shared = require('@vue/shared');
var index = require('../../upload/index2.js');
var uploadList = require('../../upload/src/upload-list4.js');
var upload = require('../../upload/src/upload3.js');
var pluginVue_exportHelper = require('../../../_virtual/plugin-vue_export-helper.js');

const _sfc_main = vue.defineComponent({
  name: "ElUploadV2",
  components: {
    ElUpload: index.ElUpload,
    ElUploadList: uploadList["default"]
  },
  props: {
    value: {
      type: [Array, String],
      default: () => {
        return "";
      }
    },
    maxFileSize: {
      type: Number,
      default: 3e6
    },
    width: {
      type: Number,
      default: 400
    },
    height: {
      type: Number,
      default: 400
    },
    size: {
      type: Number,
      default: 3
    },
    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
    },
    showCropper: {
      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,
      values: upload.uploadListTypes,
      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 = value ? [value] : [];
      } else {
        fileList.value = value;
      }
    });
    const fileUrlList = vue.computed(() => {
      if (isSingleUpload.value) {
        return [{ url: 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
    };
  }
});
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  const _component_ElUploadList = vue.resolveComponent("ElUploadList");
  const _component_ElUpload = vue.resolveComponent("ElUpload");
  return vue.openBlock(), vue.createBlock(_component_ElUpload, vue.mergeProps(_ctx.uploadProps, {
    "file-list": _ctx.fileUrlList,
    "show-file-list": !_ctx.isSingleUpload,
    "on-remove": _ctx.onRemove,
    "on-change": _ctx.onChange
  }), {
    default: vue.withCtx(() => [
      _ctx.isSingleUpload && _ctx.uploadProps.value ? (vue.openBlock(), vue.createBlock(_component_ElUploadList, {
        key: 0,
        "list-type": "picture-card",
        files: _ctx.getFileList(_ctx.uploadProps.value),
        "customer-class": "qd-upload-list--single",
        onRemove: _ctx.onRemove
      }, null, 8, ["files", "onRemove"])) : vue.createCommentVNode("v-if", true)
    ]),
    _: 1
  }, 16, ["file-list", "show-file-list", "on-remove", "on-change"]);
}
var UploadV2 = /* @__PURE__ */ pluginVue_exportHelper["default"](_sfc_main, [["render", _sfc_render], ["__file", "/Users/wyf/work/element-plus/packages/components/upload-v2/src/index.vue"]]);

exports["default"] = UploadV2;
//# sourceMappingURL=index2.js.map
