'use strict';

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

var vue = require('vue');
require('../../../utils/index.js');
var antDesignVue = require('ant-design-vue');
var upload = require('./upload.js');
var createNamespace = require('../../../utils/create-namespace.js');
var file = require('../../../utils/file.js');

"use strict";
var _sfc_main = /* @__PURE__ */ vue.defineComponent({
  ...{ name: "LlUpload" },
  __name: "upload",
  props: upload.uploadProps,
  emits: ["update:fileList", "change"],
  setup(__props, { emit: __emit }) {
    const attrs = vue.useAttrs();
    const bem = createNamespace.createNamespace("upload");
    const props = __props;
    const emits = __emit;
    const rejectUid = vue.ref([]);
    const currentFileList = vue.computed({
      get: () => props.fileList,
      set: (val) => {
        emits("update:fileList", val);
        emits("change", val);
      }
    });
    const beforeUpload = async (file$1, fileList) => {
      let isType = true;
      let isSize = true;
      if (!file.matchAcceptType(file$1, props.accept)) {
        antDesignVue.message.error(`${file$1.name} \u9700\u8981\u4E3A${props.accept}\u683C\u5F0F\u3002`);
        isType = false;
      }
      if (props.imgSize > 0) {
        const fileSizeInMB = file$1.size / (1024 * 1024);
        if (fileSizeInMB > props.imgSize) {
          antDesignVue.message.error(
            `${file$1.name} \u6587\u4EF6\u4E0D\u5F97\u5927\u4E8E${file.formatFileSize(
              props.imgSize * 1024 * 1024
            )}\u3002`
          );
          isSize = false;
        }
      }
      if (!(isType && isSize)) {
        rejectUid.value.push(file$1.uid);
        return Promise.reject(false);
      }
      if (!props.beforeUpload?.(file$1, fileList)) {
        rejectUid.value.push(file$1.uid);
        return Promise.reject(false);
      }
      return Promise.resolve();
    };
    const handleChange = ({
      fileList
    }) => {
      const files = fileList.filter(
        (item) => rejectUid.value.indexOf(item.uid) === -1
      );
      currentFileList.value = files;
    };
    const currentListType = vue.computed(() => {
      return props.operateStyle === "card" ? "picture-card" : props.listType;
    });
    return (_ctx, _cache) => {
      const _component_ll_icon = vue.resolveComponent("ll-icon");
      const _component_a_upload_dragger = vue.resolveComponent("a-upload-dragger");
      const _component_ll_button = vue.resolveComponent("ll-button");
      const _component_a_upload = vue.resolveComponent("a-upload");
      return vue.openBlock(), vue.createElementBlock(
        vue.Fragment,
        null,
        [
          vue.createCommentVNode(" \u62D6\u62FD\u4E0A\u4F20 "),
          _ctx.operateStyle === "drag" ? (vue.openBlock(), vue.createBlock(_component_a_upload_dragger, vue.mergeProps({
            key: 0,
            "file-list": currentFileList.value,
            "onUpdate:fileList": _cache[0] || (_cache[0] = ($event) => currentFileList.value = $event)
          }, vue.unref(attrs), {
            accept: props.accept,
            "before-upload": beforeUpload,
            "list-type": currentListType.value,
            class: [vue.unref(bem).b(), vue.unref(bem).is("drag"), _ctx.disabled ? vue.unref(bem).is("disabled") : ""],
            disabled: _ctx.disabled,
            onChange: handleChange
          }), {
            default: vue.withCtx(() => [
              vue.createVNode(_component_ll_icon, {
                "icon-name": _ctx.uploadIcon || "icon-upload",
                size: _ctx.uploadIconSize
              }, null, 8, ["icon-name", "size"]),
              vue.createCommentVNode(" \u4E0A\u4F20\u6807\u9898 "),
              _ctx.uploadTitle ? (vue.openBlock(), vue.createElementBlock(
                "div",
                {
                  key: 0,
                  class: vue.normalizeClass(vue.unref(bem).m("upload-title"))
                },
                vue.toDisplayString(_ctx.uploadTitle),
                3
                /* TEXT, CLASS */
              )) : vue.createCommentVNode("v-if", true),
              vue.createCommentVNode(" \u4E0A\u4F20\u63D0\u793A "),
              _ctx.uploadTip ? (vue.openBlock(), vue.createElementBlock(
                "div",
                {
                  key: 1,
                  class: vue.normalizeClass(vue.unref(bem).m("upload-tip"))
                },
                vue.toDisplayString(_ctx.uploadTip),
                3
                /* TEXT, CLASS */
              )) : vue.createCommentVNode("v-if", true)
            ]),
            _: 1
            /* STABLE */
          }, 16, ["file-list", "accept", "list-type", "class", "disabled"])) : (vue.openBlock(), vue.createElementBlock(
            vue.Fragment,
            { key: 1 },
            [
              vue.createCommentVNode(" \u9ED8\u8BA4\u4E0A\u4F20 "),
              vue.createVNode(_component_a_upload, vue.mergeProps(vue.unref(attrs), {
                "file-list": currentFileList.value,
                "onUpdate:fileList": _cache[1] || (_cache[1] = ($event) => currentFileList.value = $event),
                accept: props.accept,
                "before-upload": beforeUpload,
                class: [vue.unref(bem).b(), vue.unref(bem).is("default")],
                "list-type": currentListType.value,
                disabled: _ctx.disabled,
                onDragenterCapture: _cache[2] || (_cache[2] = vue.withModifiers(() => {
                }, ["stop"])),
                onDragoverCapture: _cache[3] || (_cache[3] = vue.withModifiers(() => {
                }, ["stop"])),
                onDropCapture: _cache[4] || (_cache[4] = vue.withModifiers(() => {
                }, ["stop"])),
                onChange: handleChange
              }), vue.createSlots({
                default: vue.withCtx(() => [
                  _ctx.operateStyle === "card" ? (vue.openBlock(), vue.createElementBlock(
                    "div",
                    {
                      key: 0,
                      class: vue.normalizeClass(vue.unref(bem).is("card"))
                    },
                    [
                      vue.createVNode(_component_ll_icon, {
                        "icon-name": _ctx.uploadIcon || "icon-upload",
                        size: _ctx.uploadIconSize
                      }, null, 8, ["icon-name", "size"]),
                      _ctx.uploadTitle ? (vue.openBlock(), vue.createElementBlock(
                        "div",
                        {
                          key: 0,
                          class: vue.normalizeClass(vue.unref(bem).m("upload-title"))
                        },
                        vue.toDisplayString(_ctx.uploadTitle),
                        3
                        /* TEXT, CLASS */
                      )) : vue.createCommentVNode("v-if", true)
                    ],
                    2
                    /* CLASS */
                  )) : (vue.openBlock(), vue.createElementBlock(
                    vue.Fragment,
                    { key: 1 },
                    [
                      vue.createCommentVNode(" \u6309\u94AE\u98CE\u683C "),
                      vue.createElementVNode(
                        "div",
                        {
                          class: vue.normalizeClass(vue.unref(bem).is("button"))
                        },
                        [
                          vue.createVNode(_component_ll_button, { disabled: _ctx.disabled }, {
                            default: vue.withCtx(() => [
                              vue.createVNode(_component_ll_icon, {
                                "icon-name": _ctx.uploadIcon || "icon-upload",
                                size: _ctx.uploadIconSize
                              }, null, 8, ["icon-name", "size"]),
                              _ctx.uploadTitle ? (vue.openBlock(), vue.createElementBlock(
                                "div",
                                {
                                  key: 0,
                                  class: vue.normalizeClass(vue.unref(bem).m("upload-title"))
                                },
                                vue.toDisplayString(_ctx.uploadTitle),
                                3
                                /* TEXT, CLASS */
                              )) : vue.createCommentVNode("v-if", true)
                            ]),
                            _: 1
                            /* STABLE */
                          }, 8, ["disabled"]),
                          vue.createCommentVNode(" \u4E0A\u4F20\u63D0\u793A "),
                          _ctx.uploadTip ? (vue.openBlock(), vue.createElementBlock(
                            "div",
                            {
                              key: 0,
                              class: vue.normalizeClass(vue.unref(bem).m("upload-tip"))
                            },
                            vue.toDisplayString(_ctx.uploadTip),
                            3
                            /* TEXT, CLASS */
                          )) : vue.createCommentVNode("v-if", true)
                        ],
                        2
                        /* CLASS */
                      )
                    ],
                    2112
                    /* STABLE_FRAGMENT, DEV_ROOT_FRAGMENT */
                  ))
                ]),
                _: 2
                /* DYNAMIC */
              }, [
                vue.renderList(Object.keys(_ctx.$slots), (item) => {
                  return {
                    name: item,
                    fn: vue.withCtx((data) => [
                      vue.renderSlot(_ctx.$slots, item, vue.normalizeProps(vue.guardReactiveProps(data || {})))
                    ])
                  };
                })
              ]), 1040, ["file-list", "accept", "class", "list-type", "disabled"])
            ],
            2112
            /* STABLE_FRAGMENT, DEV_ROOT_FRAGMENT */
          )),
          vue.createCommentVNode(" \u4E0A\u4F20\u63D0\u793A "),
          _ctx.uploadTip && _ctx.operateStyle === "card" ? (vue.openBlock(), vue.createElementBlock(
            "div",
            {
              key: 2,
              class: vue.normalizeClass(vue.unref(bem).m("upload-tip"))
            },
            vue.toDisplayString(_ctx.uploadTip),
            3
            /* TEXT, CLASS */
          )) : vue.createCommentVNode("v-if", true)
        ],
        64
        /* STABLE_FRAGMENT */
      );
    };
  }
});

exports.default = _sfc_main;
//# sourceMappingURL=upload.vue2.js.map
