import { defineComponent, ref, computed, watch, resolveComponent, openBlock, createBlock, mergeProps, createSlots, withCtx, createCommentVNode, renderSlot } from 'vue';
import { NOOP } from '@vue/shared';
import { ElUpload } from '../../upload/index.mjs';
import ElUploadList from '../../upload/src/upload-list2.mjs';
import { uploadListTypes } from '../../upload/src/upload.mjs';
import _export_sfc from '../../../../_virtual/plugin-vue_export-helper.mjs';

const _sfc_main = defineComponent({
  name: "ElUploadV2",
  components: {
    ElUpload,
    ElUploadList
  },
  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) => file.data.list[0].raw
    },
    autoUpload: {
      type: Boolean,
      default: true
    },
    listType: {
      type: String,
      values: uploadListTypes,
      default: "picture-card"
    },
    httpRequest: {
      type: Function
    },
    disabled: Boolean,
    limit: {
      type: Number,
      default: null
    },
    onExceed: {
      type: Function,
      default: () => NOOP
    },
    showDelete: {
      type: Boolean,
      default: true
    },
    beforeUpload: {
      type: Function
    },
    showDraggable: {
      type: Boolean,
      default: false
    },
    onDraggable: {
      type: Function,
      default: () => 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 fileList = ref([]);
    const isSingleUpload = computed(() => {
      return props.type === "single";
    });
    watch(() => props.value, (value) => {
      if (props.type === "single") {
        fileList.value = value ? [value] : [];
      } else {
        fileList.value = value;
      }
    });
    const fileUrlList = 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 = (list) => {
      emit("update:value", getEmitValue(list));
    };
    const onRemove = (file, fileList2) => {
      if (!fileList2) {
        emit("update:value", isSingleUpload.value ? "" : []);
        emit("remove", isSingleUpload.value ? "" : []);
        return;
      }
      emit("update:value", getEmitValue(fileList2.map((e) => e.url)));
      emit("remove", getEmitValue(fileList2.map((e) => e.url)));
    };
    const onChange = (list) => {
      if (!list) {
        return;
      }
      emit("update:value", getEmitValue(list));
    };
    const getFileList = (file) => {
      return [{ url: file }];
    };
    const onDraggabled = (fileList2) => {
      const files = getEmitValue(fileList2.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 = resolveComponent("ElUploadList");
  const _component_ElUpload = resolveComponent("ElUpload");
  return openBlock(), createBlock(_component_ElUpload, 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-draggable": _ctx.onDraggabled,
    "btn-text": _ctx.btnText,
    "list-type": "picture-card",
    "on-append-click": _ctx.onAppendClick
  }), createSlots({
    default: withCtx(() => [
      _ctx.isSingleUpload && _ctx.uploadProps.value ? (openBlock(), 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"])) : createCommentVNode("v-if", true)
    ]),
    _: 2
  }, [
    _ctx.$slots.tip ? {
      name: "tip",
      fn: withCtx(() => [
        renderSlot(_ctx.$slots, "tip")
      ])
    } : void 0
  ]), 1040, ["file-list", "show-file-list", "show-draggable", "show-preview", "on-remove", "on-change", "on-draggable", "btn-text", "on-append-click"]);
}
var UploadV2 = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render], ["__file", "/home/kimihiro/workfiles/dingdandao/element-plus/packages/components/upload-v2/src/index.vue"]]);

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