'use strict';

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

var vue = require('vue');
require('../../../tokens/index.js');
require('../../../hooks/index.js');
var uploadList = require('./upload-list2.js');
var uploadContent = require('./upload-content2.js');
var useHandlers = require('./use-handlers.js');
var upload = require('./upload.js');
var pluginVue_exportHelper = require('../../../../_virtual/plugin-vue_export-helper.js');
var index = require('../../../hooks/use-namespace/index.js');
var index$1 = require('../../../hooks/use-common-props/index.js');
var upload$1 = require('../../../tokens/upload.js');

const __default__ = vue.defineComponent({
  name: "ElUpload"
});
const _sfc_main = /* @__PURE__ */ vue.defineComponent({
  ...__default__,
  props: upload.uploadProps,
  setup(__props, { expose }) {
    const props = __props;
    const ns = index.useNamespace("upload");
    const slots = vue.useSlots();
    const disabled = index$1.useDisabled();
    const uploadRef = vue.shallowRef();
    const {
      abort,
      submit,
      clearFiles,
      uploadFiles,
      handleStart,
      handleError,
      handleRemove,
      handleSuccess,
      handleProgress,
      handleDraggable
    } = useHandlers.useHandlers(props, uploadRef);
    const isPictureCard = vue.computed(() => props.listType === "picture-card");
    const uploadContentProps = vue.computed(() => ({
      ...props,
      fileList: uploadFiles.value,
      onStart: handleStart,
      onProgress: handleProgress,
      onSuccess: handleSuccess,
      onError: handleError,
      onRemove: handleRemove
    }));
    vue.onBeforeUnmount(() => {
      uploadFiles.value.forEach(({ url }) => {
        if (url == null ? void 0 : url.startsWith("blob:"))
          URL.revokeObjectURL(url);
      });
    });
    vue.provide(upload$1.uploadContextKey, {
      accept: vue.toRef(props, "accept")
    });
    expose({
      abort,
      submit,
      clearFiles,
      handleStart,
      handleRemove
    });
    return (_ctx, _cache) => {
      return vue.openBlock(), vue.createElementBlock("div", {
        class: vue.normalizeClass({
          [vue.unref(ns).e("contain")]: ["picture-card"].includes(props.listType)
        })
      }, [
        vue.unref(isPictureCard) && _ctx.showFileList ? (vue.openBlock(), vue.createBlock(uploadList["default"], {
          key: 0,
          disabled: vue.unref(disabled),
          "list-type": _ctx.listType,
          files: vue.unref(uploadFiles),
          "show-draggable": props.showDraggable,
          "show-preview": props.showPreview,
          "handle-preview": _ctx.onPreview,
          onRemove: vue.unref(handleRemove),
          onDraggable: vue.unref(handleDraggable)
        }, vue.createSlots({ _: 2 }, [
          _ctx.$slots.file ? {
            name: "default",
            fn: vue.withCtx(({ file }) => [
              vue.renderSlot(_ctx.$slots, "file", { file })
            ])
          } : void 0,
          _ctx.limit && _ctx.limit > vue.unref(uploadFiles).length || !_ctx.limit ? {
            name: "append",
            fn: vue.withCtx(() => [
              vue.createVNode(uploadContent["default"], vue.mergeProps({
                ref_key: "uploadRef",
                ref: uploadRef
              }, vue.unref(uploadContentProps)), {
                default: vue.withCtx(() => [
                  vue.unref(slots).trigger ? vue.renderSlot(_ctx.$slots, "trigger", { key: 0 }) : vue.createCommentVNode("v-if", true),
                  !vue.unref(slots).trigger && vue.unref(slots).default ? vue.renderSlot(_ctx.$slots, "default", { key: 1 }) : vue.createCommentVNode("v-if", true)
                ]),
                _: 3
              }, 16)
            ])
          } : void 0
        ]), 1032, ["disabled", "list-type", "files", "show-draggable", "show-preview", "handle-preview", "onRemove", "onDraggable"])) : vue.createCommentVNode("v-if", true),
        !vue.unref(isPictureCard) || vue.unref(isPictureCard) && !_ctx.showFileList ? (vue.openBlock(), vue.createBlock(uploadContent["default"], vue.mergeProps({
          key: 1,
          ref_key: "uploadRef",
          ref: uploadRef
        }, vue.unref(uploadContentProps)), {
          default: vue.withCtx(() => [
            vue.unref(slots).trigger ? vue.renderSlot(_ctx.$slots, "trigger", { key: 0 }) : vue.createCommentVNode("v-if", true),
            !vue.unref(slots).trigger && vue.unref(slots).default ? vue.renderSlot(_ctx.$slots, "default", { key: 1 }) : vue.createCommentVNode("v-if", true)
          ]),
          _: 3
        }, 16)) : vue.createCommentVNode("v-if", true),
        _ctx.$slots.trigger ? vue.renderSlot(_ctx.$slots, "default", { key: 2 }) : vue.createCommentVNode("v-if", true),
        _ctx.$slots.tip ? (vue.openBlock(), vue.createElementBlock("div", {
          key: 3,
          class: vue.normalizeClass(vue.unref(ns).b(props.type === "single" ? "single-tip" : "tip"))
        }, [
          vue.renderSlot(_ctx.$slots, "tip")
        ], 2)) : vue.createCommentVNode("v-if", true),
        !vue.unref(isPictureCard) && _ctx.showFileList ? (vue.openBlock(), vue.createBlock(uploadList["default"], {
          key: 4,
          disabled: vue.unref(disabled),
          "list-type": _ctx.listType,
          files: vue.unref(uploadFiles),
          "show-draggable": props.showDraggable,
          "show-preview": props.showPreview,
          "handle-preview": _ctx.onPreview,
          onRemove: vue.unref(handleRemove),
          onDraggable: vue.unref(handleDraggable)
        }, vue.createSlots({ _: 2 }, [
          _ctx.$slots.file ? {
            name: "default",
            fn: vue.withCtx(({ file }) => [
              vue.renderSlot(_ctx.$slots, "file", { file })
            ])
          } : void 0
        ]), 1032, ["disabled", "list-type", "files", "show-draggable", "show-preview", "handle-preview", "onRemove", "onDraggable"])) : vue.createCommentVNode("v-if", true)
      ], 2);
    };
  }
});
var Upload = /* @__PURE__ */ pluginVue_exportHelper["default"](_sfc_main, [["__file", "/home/dingdan/workspace/element-plus/packages/components/upload/src/upload.vue"]]);

exports["default"] = Upload;
//# sourceMappingURL=upload2.js.map
