/**
 * ldesign v0.2.2
 * (c) 2022年9月20日 swimly
 * @license MIT
 */

'use strict';

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

var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var iconsVue = require('@ldesign/icons-vue');
var components_loading_index = require('../loading/index.js');
var components_upload_props = require('./props.js');
var utils_mixins = require('../../utils/mixins.js');
var components_configProvider_configReceiver = require('../config-provider/config-receiver.js');
require('../loading/loading.js');
require('../loading/icon/gradient.js');
require('vue');
require('../../chunks/defineProperty-28395935.js');
require('../../chunks/set-style.js');
require('../../chunks/helper2.js');
require('@babel/runtime/helpers/toConsumableArray');
require('@babel/runtime/helpers/slicedToArray');
require('../../config.js');
require('../../utils/dom.js');
require('raf');
require('lodash/isString');
require('../../utils/easing.js');
require('../../utils/render-node.js');
require('@babel/runtime/helpers/typeof');
require('lodash/camelCase');
require('lodash/kebabCase');
require('../../utils/transfer-dom.js');
require('../loading/props.js');
require('lodash/mergeWith');
require('lodash');
require('../config-provider/context.js');
require('../../chunks/zh_CN.js');
require('../../utils/with-install.js');
require('../loading/plugin.js');

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

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

var LImageCard = utils_mixins["default"](components_configProvider_configReceiver["default"]("upload"), components_configProvider_configReceiver.getGlobalIconMixins()).extend({
  name: "LImageUpload",
  components: {
    TLoading: components_loading_index.Loading
  },
  props: {
    showUploadProgress: components_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: iconsVue.AddIcon,
      DeleteIcon: iconsVue.DeleteIcon,
      BrowseIcon: iconsVue.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(components_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"] = LImageCard;
//# sourceMappingURL=image.js.map
