'use strict';

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

var vue = require('vue');
var shared = require('@vue/shared');
var index = require('../../upload/index.js');
var uploadList = require('../../upload/src/upload-list2.js');
var upload = require('../../upload/src/upload.js');
var index$1 = require('../../message/index.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: "image/*"
    },
    type: {
      type: String,
      default: "select"
    },
    responseHandle: {
      type: Function,
      default: (file) => {
        var _a, _b, _c;
        const result = ((_c = (_b = (_a = file.data) == null ? void 0 : _a.list) == null ? void 0 : _b[0]) == null ? void 0 : _c.raw) || "";
        if (!result && file.msg) {
          index$1.ElMessage.error(file.msg);
        }
        return result;
      }
    },
    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
    },
    showDelete: {
      type: Boolean,
      default: true
    },
    beforeUpload: {
      type: Function
    },
    showDraggable: {
      type: Boolean,
      default: false
    },
    onDraggable: {
      type: Function,
      default: () => shared.NOOP
    },
    onAppendClick: {
      type: Function
    },
    showPreview: {
      type: Boolean,
      default: false
    },
    btnText: {
      type: String,
      default: "\u6DFB\u52A0\u56FE\u7247"
    }
  },
  emits: ["update:value", "remove"],
  setup(props, { emit }) {
    const isSingleUpload = vue.computed(() => {
      return props.type === "single";
    });
    const fileUrlList = vue.computed(() => {
      if (isSingleUpload.value) {
        return [{ url: props.value }];
      } else {
        return props.value.map((e) => ({
          url: e
        }));
      }
    });
    const getEmitValue = (fileList) => {
      if (isSingleUpload.value) {
        return fileList[0];
      } else {
        return fileList;
      }
    };
    const onSuccess = (list) => {
      emit("update:value", getEmitValue(list));
    };
    const onRemove = (file, fileList) => {
      if (!fileList) {
        emit("update:value", isSingleUpload.value ? "" : []);
        emit("remove", isSingleUpload.value ? "" : []);
        return;
      }
      emit("update:value", getEmitValue(fileList.map((e) => e.url)));
      emit("remove", getEmitValue(fileList.map((e) => e.url)));
    };
    const onChange = (list) => {
      if (!list) {
        return;
      }
      emit("update:value", getEmitValue(list));
    };
    const getFileList = (file) => {
      return [{ url: file }];
    };
    const onDraggabled = (fileList) => {
      const files = getEmitValue(fileList.map((e) => e.url));
      emit("update:value", files);
      props.onDraggable && props.onDraggable(files);
    };
    return {
      uploadProps: props,
      fileUrlList,
      onSuccess,
      onRemove,
      onChange,
      isSingleUpload,
      getFileList,
      onDraggabled
    };
  }
});
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,
    "show-draggable": _ctx.showDraggable,
    "show-preview": _ctx.showPreview,
    "on-remove": _ctx.onRemove,
    "on-change": _ctx.onChange,
    "on-success": _ctx.onSuccess,
    "on-draggable": _ctx.onDraggabled,
    "btn-text": _ctx.btnText,
    "list-type": "picture-card",
    "on-append-click": _ctx.onAppendClick
  }), vue.createSlots({
    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",
        "show-delete": _ctx.showDelete,
        "on-append-click": _ctx.onAppendClick,
        "show-preview": _ctx.showPreview,
        onRemove: _ctx.onRemove
      }, null, 8, ["files", "show-delete", "on-append-click", "show-preview", "onRemove"])) : vue.createCommentVNode("v-if", true)
    ]),
    _: 2
  }, [
    _ctx.$slots.tip ? {
      name: "tip",
      fn: vue.withCtx(() => [
        vue.renderSlot(_ctx.$slots, "tip")
      ])
    } : void 0,
    _ctx.$slots.default ? {
      name: "default",
      fn: vue.withCtx(() => [
        vue.renderSlot(_ctx.$slots, "default")
      ])
    } : void 0,
    _ctx.$slots.file ? {
      name: "file",
      fn: vue.withCtx(() => [
        vue.renderSlot(_ctx.$slots, "file")
      ])
    } : void 0,
    _ctx.$slots.trigger ? {
      name: "trigger",
      fn: vue.withCtx(() => [
        vue.renderSlot(_ctx.$slots, "trigger")
      ])
    } : void 0
  ]), 1040, ["file-list", "show-file-list", "show-draggable", "show-preview", "on-remove", "on-change", "on-success", "on-draggable", "btn-text", "on-append-click"]);
}
var UploadV2 = /* @__PURE__ */ pluginVue_exportHelper["default"](_sfc_main, [["render", _sfc_render], ["__file", "/home/lxj/workspace/element-plus/packages/components/upload-v2/src/index.vue"]]);

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