/**
 * tdesign v0.32.0
 * (c) 2021 tdesign
 * @license MIT
 */

import _defineProperty from '@babel/runtime/helpers/defineProperty';
import Vue from 'vue';
import { AddIcon, DeleteIcon, UploadIcon, BrowseIcon } from 'tdesign-icons-vue';
import { Loading } from '../loading/index.js';
import { UPLOAD_NAME } from './util.js';
import props from './props.js';
import { prefix } from '../config.js';
import ClASSNAMES from '../utils/classnames.js';
import '../loading/loading.js';
import '../loading/icon/gradient.js';
import '../utils/set-style.js';
import '../utils/dom.js';
import 'raf';
import 'lodash/isString';
import '../utils/easing.js';
import '../utils/render-tnode.js';
import '@babel/runtime/helpers/typeof';
import '../utils/transfer-dom.js';
import '../loading/props.js';
import '../utils/withInstall.js';
import 'lodash/capitalize';
import './style/css.js';
import '../loading/type.js';
import '../loading/plugin.js';

var ImageCard = Vue.extend({
  name: "TImageUpload",
  components: {
    TIconAdd: AddIcon,
    IIconDelete: DeleteIcon,
    IIconUpload: UploadIcon,
    TIconBrowse: BrowseIcon,
    TLoading: Loading
  },
  props: {
    showUploadProgress: props.showUploadProgress,
    files: {
      type: Array
    },
    loadingFile: {
      type: Object
    },
    trigger: {
      type: Function
    },
    remove: {
      type: Function
    },
    multiple: Boolean,
    max: Number,
    disabled: Boolean
  },
  computed: {
    showTrigger: function showTrigger() {
      if (this.multiple) {
        return !this.max || this.files.length < this.max;
      }

      return !(this.files && this.files[0]);
    }
  },
  methods: {
    onMaskClick: function onMaskClick(e) {
      !this.showTrigger && this.trigger(e);
    },
    onViewClick: function onViewClick(e, file) {
      this.$emit("imgPreview", e, file);
    }
  },
  render: function render() {
    var _this = this;

    var h = arguments[0];
    return h("ul", {
      "class": "".concat(UPLOAD_NAME, "__card")
    }, [this.files && this.files.map(function (file, index) {
      return h("li", {
        "class": "".concat(UPLOAD_NAME, "__card-item ").concat(prefix, "-is--background")
      }, [h("div", {
        "class": "".concat(UPLOAD_NAME, "__card-content ").concat(UPLOAD_NAME, "__card-box")
      }, [h("img", {
        "class": "".concat(UPLOAD_NAME, "__card-image"),
        "attrs": {
          "src": file.url
        }
      }), h("div", {
        "class": "".concat(UPLOAD_NAME, "__card-mask"),
        "on": {
          "click": _this.onMaskClick
        }
      }, [h("span", {
        "class": "".concat(UPLOAD_NAME, "__card-mask-item"),
        "on": {
          "click": function click(e) {
            return e.stopPropagation();
          }
        }
      }, [h(BrowseIcon, {
        "nativeOn": {
          "click": function click(e) {
            return _this.onViewClick(e, file);
          }
        }
      })]), h("span", {
        "class": "".concat(UPLOAD_NAME, "__card-mask-item-divider")
      }), h("span", {
        "class": "".concat(UPLOAD_NAME, "__card-mask-item"),
        "on": {
          "click": function click(e) {
            return e.stopPropagation();
          }
        }
      }, [h(DeleteIcon, {
        "nativeOn": {
          "click": function click(e) {
            return _this.remove({
              e: e,
              file: file,
              index: index
            });
          }
        }
      })])])])]);
    }), this.showTrigger && h("li", {
      "class": ["".concat(UPLOAD_NAME, "__card-item ").concat(prefix, "-is--background"), _defineProperty({}, ClASSNAMES.STATUS.disabled, this.disabled)],
      "on": {
        "click": this.trigger
      }
    }, [this.showUploadProgress && this.loadingFile && this.loadingFile.status === "progress" ? h("div", {
      "class": "".concat(UPLOAD_NAME, "__card-container ").concat(UPLOAD_NAME, "__card-box")
    }, [h(Loading), h("p", ["\u4E0A\u4F20\u4E2D ", Math.min(this.loadingFile.percent, 99), "%"])]) : h("div", {
      "class": "".concat(UPLOAD_NAME, "__card-container ").concat(UPLOAD_NAME, "__card-box")
    }, [h(AddIcon), h("p", {
      "class": "".concat(prefix, "-size-s")
    }, ["\u70B9\u51FB\u4E0A\u4F20\u56FE\u7247"])])])]);
  }
});

export { ImageCard as default };
//# sourceMappingURL=image.js.map
