"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
const Vue = require("vue");
const utils = require("./utils.js");
const index$1 = require("../icon/index.js");
const index = require("../image/index.js");
const index$2 = require("../loading/index.js");
const props = require("../utils/props.js");
const format = require("../utils/format.js");
const basic = require("../utils/basic.js");
const interceptor = require("../utils/interceptor.js");
var stdin_default = Vue.defineComponent({
  props: {
    name: props.numericProp,
    item: props.makeRequiredProp(Object),
    index: Number,
    imageFit: String,
    lazyLoad: Boolean,
    deletable: Boolean,
    reupload: Boolean,
    previewSize: [Number, String, Array],
    beforeDelete: Function
  },
  emits: ["delete", "preview", "reupload"],
  setup(props2, {
    emit,
    slots
  }) {
    const renderMask = () => {
      const {
        status,
        message
      } = props2.item;
      if (status === "uploading" || status === "failed") {
        const MaskIcon = status === "failed" ? Vue.createVNode(index$1.Icon, {
          "name": "close",
          "class": utils.bem("mask-icon")
        }, null) : Vue.createVNode(index$2.Loading, {
          "class": utils.bem("loading")
        }, null);
        const showMessage = basic.isDef(message) && message !== "";
        return Vue.createVNode("div", {
          "class": utils.bem("mask")
        }, [MaskIcon, showMessage && Vue.createVNode("div", {
          "class": utils.bem("mask-message")
        }, [message])]);
      }
    };
    const onDelete = (event) => {
      const {
        name,
        item,
        index: index2,
        beforeDelete
      } = props2;
      event.stopPropagation();
      interceptor.callInterceptor(beforeDelete, {
        args: [item, {
          name,
          index: index2
        }],
        done: () => emit("delete")
      });
    };
    const onPreview = () => emit("preview");
    const onReupload = () => emit("reupload");
    const renderDeleteIcon = () => {
      if (props2.deletable && props2.item.status !== "uploading") {
        const slot = slots["preview-delete"];
        return Vue.createVNode("div", {
          "role": "button",
          "class": utils.bem("preview-delete", {
            shadow: !slot
          }),
          "tabindex": 0,
          "aria-label": utils.t("delete"),
          "onClick": onDelete
        }, [slot ? slot() : Vue.createVNode(index$1.Icon, {
          "name": "cross",
          "class": utils.bem("preview-delete-icon")
        }, null)]);
      }
    };
    const renderCover = () => {
      if (slots["preview-cover"]) {
        const {
          index: index2,
          item
        } = props2;
        return Vue.createVNode("div", {
          "class": utils.bem("preview-cover")
        }, [slots["preview-cover"](basic.extend({
          index: index2
        }, item))]);
      }
    };
    const renderPreview = () => {
      const {
        item,
        lazyLoad,
        imageFit,
        previewSize,
        reupload
      } = props2;
      if (utils.isImageFile(item)) {
        return Vue.createVNode(index.Image, {
          "fit": imageFit,
          "src": item.objectUrl || item.content || item.url,
          "class": utils.bem("preview-image"),
          "width": Array.isArray(previewSize) ? previewSize[0] : previewSize,
          "height": Array.isArray(previewSize) ? previewSize[1] : previewSize,
          "lazyLoad": lazyLoad,
          "onClick": reupload ? onReupload : onPreview
        }, {
          default: renderCover
        });
      }
      return Vue.createVNode("div", {
        "class": utils.bem("file"),
        "style": format.getSizeStyle(props2.previewSize)
      }, [Vue.createVNode(index$1.Icon, {
        "class": utils.bem("file-icon"),
        "name": "description"
      }, null), Vue.createVNode("div", {
        "class": [utils.bem("file-name"), "van-ellipsis"]
      }, [item.file ? item.file.name : item.url]), renderCover()]);
    };
    return () => Vue.createVNode("div", {
      "class": utils.bem("preview")
    }, [renderPreview(), renderMask(), renderDeleteIcon()]);
  }
});
exports.default = stdin_default;
