import { defineComponent, useAttrs, ref, computed, resolveComponent, createElementBlock, openBlock, Fragment, createCommentVNode, createBlock, mergeProps, unref, withCtx, createVNode, normalizeClass, toDisplayString, withModifiers, createSlots, createElementVNode, renderList, renderSlot, normalizeProps, guardReactiveProps } from 'vue';
import '../../../utils/index.mjs';
import { message } from 'ant-design-vue';
import { uploadProps } from './upload.mjs';
import { createNamespace } from '../../../utils/create-namespace.mjs';
import { matchAcceptType, formatFileSize } from '../../../utils/file.mjs';

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

export { _sfc_main as default };
//# sourceMappingURL=upload.vue2.mjs.map
