/**
 * tdesign v0.41.7
 * (c) 2022 tdesign
 * @license MIT
 */

'use strict';

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

var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var tdesignIconsVue = require('tdesign-icons-vue');
var loading_index = require('../loading/index.js');
var upload_props = require('./props.js');
var config = require('../config.js');
var utils_classnames = require('../utils/classnames.js');
var utils_mixins = require('../utils/mixins.js');
var configProvider_configReceiver = require('../config-provider/config-receiver.js');
require('../loading/loading.js');
require('vue');
require('../loading/icon/gradient.js');
require('../_common/js/loading/circle-adapter.js');
require('../_common/js/utils/set-style.js');
require('../_common/js/utils/helper.js');
require('@babel/runtime/helpers/objectWithoutProperties');
require('@babel/runtime/helpers/slicedToArray');
require('../utils/dom.js');
require('raf');
require('lodash/isString');
require('../utils/easing.js');
require('../utils/render-tnode.js');
require('@babel/runtime/helpers/typeof');
require('../utils/transfer-dom.js');
require('../loading/props.js');
require('../utils/withInstall.js');
require('lodash/capitalize');
require('../loading/plugin.js');
require('lodash/mergeWith');
require('../config-provider/context.js');
require('lodash/merge');
require('../_common/js/global-config/default-config.js');
require('../_common/js/global-config/locale/zh_CN.js');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);

var uploadName = "".concat(config.prefix, "-upload");
var ImageCard = utils_mixins["default"](configProvider_configReceiver["default"]("upload")).extend({
  name: "TImageUpload",
  components: {
    AddIcon: tdesignIconsVue.AddIcon,
    DeleteIcon: tdesignIconsVue.DeleteIcon,
    BrowseIcon: tdesignIconsVue.BrowseIcon,
    TLoading: loading_index.Loading
  },
  props: {
    showUploadProgress: upload_props["default"].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(uploadName, "__card")
    }, [this.files && this.files.map(function (file, index) {
      return h("li", {
        "class": "".concat(uploadName, "__card-item ").concat(config.prefix, "-is--background")
      }, [h("div", {
        "class": "".concat(uploadName, "__card-content ").concat(uploadName, "__card-box")
      }, [h("img", {
        "class": "".concat(uploadName, "__card-image"),
        "attrs": {
          "src": file.url
        }
      }), h("div", {
        "class": "".concat(uploadName, "__card-mask"),
        "on": {
          "click": _this.onMaskClick
        }
      }, [h("span", {
        "class": "".concat(uploadName, "__card-mask-item"),
        "on": {
          "click": function click(e) {
            return e.stopPropagation();
          }
        }
      }, [h(tdesignIconsVue.BrowseIcon, {
        "nativeOn": {
          "click": function click(e) {
            return _this.onViewClick(e, file);
          }
        }
      })]), !_this.disabled && [h("span", {
        "class": "".concat(uploadName, "__card-mask-item-divider"),
        "key": "divider"
      }), h("span", {
        "class": "".concat(uploadName, "__card-mask-item"),
        "on": {
          "click": function click(e) {
            return e.stopPropagation();
          }
        },
        "key": "delete-icon"
      }, [h(tdesignIconsVue.DeleteIcon, {
        "nativeOn": {
          "click": function click(e) {
            return _this.remove({
              e: e,
              file: file,
              index: index
            });
          }
        }
      })])]])])]);
    }), this.showTrigger && h("li", {
      "class": ["".concat(uploadName, "__card-item ").concat(config.prefix, "-is--background"), _defineProperty__default["default"]({}, utils_classnames["default"].STATUS.disabled, this.disabled)],
      "on": {
        "click": this.trigger
      }
    }, [this.showUploadProgress && this.loadingFile && this.loadingFile.status === "progress" ? h("div", {
      "class": "".concat(uploadName, "__card-container ").concat(uploadName, "__card-box")
    }, [h(loading_index.Loading), h("p", [this.global.progress.uploadingText, " ", Math.min(this.loadingFile.percent, 99), "%"])]) : h("div", {
      "class": "".concat(uploadName, "__card-container ").concat(uploadName, "__card-box")
    }, [h(tdesignIconsVue.AddIcon), h("p", {
      "class": "".concat(config.prefix, "-size-s")
    }, [this.global.triggerUploadText.image])])])]);
  }
});

exports["default"] = ImageCard;
exports.uploadName = uploadName;
//# sourceMappingURL=image.js.map
