/**
 * tdesign v0.46.4
 * (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 utils_mixins = require('../utils/mixins.js');
var configProvider_configReceiver = require('../config-provider/config-receiver.js');
require('../loading/loading.js');
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/toConsumableArray');
require('@babel/runtime/helpers/objectWithoutProperties');
require('@babel/runtime/helpers/slicedToArray');
require('vue');
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');
require('../utils/dom.js');
require('raf');
require('lodash/isString');
require('../utils/easing.js');
require('../utils/render-tnode.js');
require('@babel/runtime/helpers/typeof');
require('lodash/camelCase');
require('lodash/kebabCase');
require('../utils/transfer-dom.js');
require('../loading/props.js');
require('../utils/withInstall.js');
require('lodash/capitalize');
require('../loading/plugin.js');
require('../config.js');

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

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

var ImageCard = utils_mixins["default"](configProvider_configReceiver["default"]("upload"), configProvider_configReceiver.getGlobalIconMixins()).extend({
  name: "TImageUpload",
  components: {
    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,
    locale: Object
  },
  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,
        _this$locale,
        _this$locale$progress,
        _this$locale2,
        _this$locale2$trigger;

    var h = arguments[0];

    var _this$useGlobalIcon = this.useGlobalIcon({
      AddIcon: tdesignIconsVue.AddIcon,
      DeleteIcon: tdesignIconsVue.DeleteIcon,
      BrowseIcon: tdesignIconsVue.BrowseIcon
    }),
        AddIcon = _this$useGlobalIcon.AddIcon,
        DeleteIcon = _this$useGlobalIcon.DeleteIcon,
        BrowseIcon = _this$useGlobalIcon.BrowseIcon;

    return h("ul", {
      "class": "".concat(this.componentName, "__card")
    }, [this.files && this.files.map(function (file, index) {
      return h("li", {
        "class": "".concat(_this.componentName, "__card-item ").concat(_this.classPrefix, "-is--background")
      }, [h("div", {
        "class": "".concat(_this.componentName, "__card-content ").concat(_this.componentName, "__card-box")
      }, [h("img", {
        "class": "".concat(_this.componentName, "__card-image"),
        "attrs": {
          "src": file.url
        }
      }), h("div", {
        "class": "".concat(_this.componentName, "__card-mask"),
        "on": {
          "click": _this.onMaskClick
        }
      }, [h("span", {
        "class": "".concat(_this.componentName, "__card-mask-item"),
        "on": {
          "click": function click(e) {
            return e.stopPropagation();
          }
        }
      }, [h(BrowseIcon, {
        "nativeOn": {
          "click": function click(e) {
            return _this.onViewClick(e, file);
          }
        }
      })]), !_this.disabled && [h("span", {
        "class": "".concat(_this.componentName, "__card-mask-item-divider"),
        "key": "divider"
      }), h("span", {
        "class": "".concat(_this.componentName, "__card-mask-item"),
        "on": {
          "click": function click(e) {
            return e.stopPropagation();
          }
        },
        "key": "delete-icon"
      }, [h(DeleteIcon, {
        "nativeOn": {
          "click": function click(e) {
            return _this.remove({
              e: e,
              file: file,
              index: index
            });
          }
        }
      })])]])])]);
    }), this.showTrigger && h("li", {
      "class": ["".concat(this.componentName, "__card-item"), "".concat(this.classPrefix, "-is--background"), _defineProperty__default["default"]({}, this.commonStatusClassName.disabled, this.disabled)],
      "on": {
        "click": this.trigger
      }
    }, [this.showUploadProgress && this.loadingFile && this.loadingFile.status === "progress" ? h("div", {
      "class": "".concat(this.componentName, "__card-container ").concat(this.componentName, "__card-box")
    }, [h(loading_index.Loading), h("p", [((_this$locale = this.locale) === null || _this$locale === void 0 ? void 0 : (_this$locale$progress = _this$locale.progress) === null || _this$locale$progress === void 0 ? void 0 : _this$locale$progress.uploadingText) || this.global.progress.uploadingText, " ", Math.min(this.loadingFile.percent, 99), "%"])]) : h("div", {
      "class": "".concat(this.componentName, "__card-container ").concat(this.componentName, "__card-box")
    }, [h(AddIcon), h("p", {
      "class": "".concat(this.classPrefix, "-size-s")
    }, [((_this$locale2 = this.locale) === null || _this$locale2 === void 0 ? void 0 : (_this$locale2$trigger = _this$locale2.triggerUploadText) === null || _this$locale2$trigger === void 0 ? void 0 : _this$locale2$trigger.image) || this.global.triggerUploadText.image])])])]);
  }
});

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