/**
 * ldesign v0.4.6
 * (c) 2023 ldesign
 * @license MIT
 */

'use strict';

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

var _toConsumableArray = require('@babel/runtime/helpers/toConsumableArray');
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var VueCompositionAPI = require('@vue/composition-api');
var iconsVue = require('@ldesign/icons-vue');
var loading_index = require('../../loading/index.js');
var hooks_useGlobalIcon = require('../../hooks/useGlobalIcon.js');
var imageViewer_index = require('../../image-viewer/index.js');
var upload_constants = require('../constants.js');
var _common_js_upload_utils = require('../../_common/js/upload/utils.js');
require('../../utils/withInstall.js');
require('vue');
require('lodash/capitalize');
require('../../loading/directive.js');
require('lodash/isObject');
require('lodash/mapKeys');
require('lodash/isEqual');
require('../../loading/plugin.js');
require('../../config.js');
require('../../utils/dom.js');
require('raf');
require('lodash/isString');
require('../../utils/easing.js');
require('../../loading/loading.js');
require('../../utils/render-tnode.js');
require('@babel/runtime/helpers/typeof');
require('lodash/camelCase');
require('lodash/kebabCase');
require('../../utils/transfer-dom.js');
require('../../config-provider/config-receiver.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');
require('../../_chunks/dep-7c884501.js');
require('dayjs');
require('../../utils/mixins.js');
require('../../loading/props.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/objectWithoutProperties');
require('@babel/runtime/helpers/slicedToArray');
require('lodash/isNull');
require('lodash/isUndefined');
require('lodash/isNumber');
require('lodash/isArray');
require('../../config-provider/useConfig.js');
require('../../image-viewer/image-viewer.js');
require('../../hooks/useVModel.js');
require('../../hooks/useDefaultValue.js');
require('../../hooks/useConfig.js');
require('../../utils/helper.js');
require('../../image-viewer/props.js');
require('../../image-viewer/base/Container.js');
require('../../image-viewer/base/ImageModalIcon.js');
require('../../hooks/tnode.js');
require('lodash/isEmpty');
require('lodash/isFunction');
require('../../hooks/render-tnode.js');
require('../../image-viewer/base/ImageViewerUtils.js');
require('../../tooltip/index.js');
require('../../utils/map-props.js');
require('../../tooltip/tooltip.js');
require('../../_chunks/dep-c3e1ffac.js');
require('../../popup/props.js');
require('../../popup/popup.js');
require('@popperjs/core');
require('../../utils/event.js');
require('../../popup/container.js');
require('../../popup/utils.js');
require('../../popup/trigger.js');
require('../../tooltip/props.js');
require('../../image-viewer/utils.js');
require('../../image-viewer/base/ImageItem.js');
require('../../image-viewer/hooks.js');
require('../../image-viewer/base/ImageViewerModal.js');
require('../../dialog/index.js');
require('../../dialog/dialog.js');
require('lodash/throttle');
require('../../button/index.js');
require('../../button/button.js');
require('../../utils/ripple.js');
require('../../button/props.js');
require('../../hooks/useDestroyOnClose.js');
require('../../_common/js/utils/getScrollbarWidth.js');
require('../../dialog/stack.js');
require('../../dialog/props.js');
require('../../dialog/actions.js');
require('../../dialog/plugin.js');
require('../../config-provider/config-provider.js');
require('lodash/cloneDeep');
require('../../image-viewer/const.js');
require('../../_common/js/log/log.js');

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

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

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty__default["default"](target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
var ImageCard = VueCompositionAPI.defineComponent({
  name: "UploadImageCard",
  props: _objectSpread(_objectSpread({}, upload_constants.commonProps), {}, {
    multiple: Boolean,
    max: Number,
    disabled: Boolean,
    showUploadProgress: Boolean,
    triggerUpload: Function,
    uploadFiles: Function,
    cancelUpload: Function
  }),
  setup: function setup(props) {
    var _toRefs = VueCompositionAPI.toRefs(props),
      displayFiles = _toRefs.displayFiles,
      multiple = _toRefs.multiple,
      max = _toRefs.max;
    var icons = hooks_useGlobalIcon.useGlobalIcon({
      AddIcon: iconsVue.AddIcon,
      BrowseIcon: iconsVue.BrowseIcon,
      DeleteIcon: iconsVue.DeleteIcon,
      ErrorCircleFilledIcon: iconsVue.ErrorCircleFilledIcon
    });
    var showTrigger = VueCompositionAPI.computed(function () {
      var _displayFiles$value;
      if (multiple.value) return !max.value || displayFiles.value.length < max.value;
      return !((_displayFiles$value = displayFiles.value) !== null && _displayFiles$value !== void 0 && _displayFiles$value[0]);
    });
    return {
      icons: icons,
      showTrigger: showTrigger
    };
  },
  methods: {
    renderMainContent: function renderMainContent(file, index) {
      var _this = this;
      var h = this.$createElement;
      var _this$icons = this.icons,
        BrowseIcon = _this$icons.BrowseIcon,
        DeleteIcon = _this$icons.DeleteIcon;
      return h("div", {
        "class": "".concat(this.classPrefix, "-upload__card-content ").concat(this.classPrefix, "-upload__card-box")
      }, [h("img", {
        "class": "".concat(this.classPrefix, "-upload__card-image"),
        "attrs": {
          "src": file.url
        }
      }), h("div", {
        "class": "".concat(this.classPrefix, "-upload__card-mask")
      }, [h("span", {
        "class": "".concat(this.classPrefix, "-upload__card-mask-item"),
        "on": {
          "click": function click(e) {
            return e.stopPropagation();
          }
        }
      }, [h(imageViewer_index.ImageViewer, {
        "attrs": {
          "images": this.displayFiles.map(function (t) {
            return t.url;
          }),
          "defaultIndex": index,
          "trigger": function trigger(h, _ref) {
            var open = _ref.open;
            return h(BrowseIcon, {
              "on": {
                "click": function click(_ref2) {
                  var e = _ref2.e;
                  _this.$emit("preview", {
                    file: file,
                    index: index,
                    e: e
                  });
                  open();
                }
              }
            });
          }
        }
      })]), !this.disabled && [h("span", {
        "class": "".concat(this.classPrefix, "-upload__card-mask-item-divider")
      }), h("span", {
        "class": "".concat(this.classPrefix, "-upload__card-mask-item"),
        "on": {
          "click": function click(e) {
            return e.stopPropagation();
          }
        }
      }, [h(DeleteIcon, {
        "on": {
          "click": function click(_ref3) {
            var _this$onRemove;
            var e = _ref3.e;
            return (_this$onRemove = _this.onRemove) === null || _this$onRemove === void 0 ? void 0 : _this$onRemove.call(_this, {
              e: e,
              file: file,
              index: index
            });
          }
        }
      })])]])]);
    },
    renderProgressFile: function renderProgressFile(file, loadCard) {
      var _this$locale, _this$locale$progress;
      var h = this.$createElement;
      return h("div", {
        "class": [loadCard, "".concat(this.classPrefix, "-upload__").concat(this.theme, "-").concat(file.status)]
      }, [h(loading_index.Loading, {
        "attrs": {
          "loading": true,
          "size": "medium"
        }
      }), 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.showUploadProgress ? " ".concat(file.percent, "%") : ""])]);
    },
    renderFailFile: function renderFailFile(file, index, loadCard) {
      var _file$response,
        _this$locale2,
        _this$locale2$progres,
        _this2 = this;
      var h = this.$createElement;
      var _this$icons2 = this.icons,
        ErrorCircleFilledIcon = _this$icons2.ErrorCircleFilledIcon,
        DeleteIcon = _this$icons2.DeleteIcon;
      return h("div", {
        "class": loadCard
      }, [h(ErrorCircleFilledIcon), h("p", [((_file$response = file.response) === null || _file$response === void 0 ? void 0 : _file$response.error) || ((_this$locale2 = this.locale) === null || _this$locale2 === void 0 ? void 0 : (_this$locale2$progres = _this$locale2.progress) === null || _this$locale2$progres === void 0 ? void 0 : _this$locale2$progres.failText)]), h("div", {
        "class": "".concat(this.classPrefix, "-upload__card-mask")
      }, [h("span", {
        "class": "".concat(this.classPrefix, "-upload__card-mask-item"),
        "on": {
          "click": function click(e) {
            return e.stopPropagation();
          }
        }
      }, [h(DeleteIcon, {
        "on": {
          "click": function click(_ref4) {
            var _this2$onRemove;
            var e = _ref4.e;
            return (_this2$onRemove = _this2.onRemove) === null || _this2$onRemove === void 0 ? void 0 : _this2$onRemove.call(_this2, {
              e: e,
              file: file,
              index: index
            });
          }
        }
      })])])]);
    }
  },
  render: function render() {
    var _this$displayFiles,
      _this3 = this,
      _this$locale3,
      _this$locale3$trigger;
    var h = arguments[0];
    var cardItemClasses = "".concat(this.classPrefix, "-upload__card-item ").concat(this.classPrefix, "-is-background");
    var AddIcon = this.icons.AddIcon;
    return h("div", [h("ul", {
      "class": "".concat(this.classPrefix, "-upload__card")
    }, [(_this$displayFiles = this.displayFiles) === null || _this$displayFiles === void 0 ? void 0 : _this$displayFiles.map(function (file, index) {
      var loadCard = "".concat(_this3.classPrefix, "-upload__card-container ").concat(_this3.classPrefix, "-upload__card-box");
      var fileName = _this3.abridgeName ? _common_js_upload_utils.abridgeName.apply(void 0, [file.name].concat(_toConsumableArray__default["default"](_this3.abridgeName))) : file.name;
      return h("li", {
        "class": cardItemClasses,
        "key": index
      }, [file.status === "progress" && _this3.renderProgressFile(file, loadCard), file.status === "fail" && _this3.renderFailFile(file, index, loadCard), !["progress", "fail"].includes(file.status) && file.url && _this3.renderMainContent(file, index), h("div", {
        "class": "".concat(_this3.classPrefix, "-upload__card-name")
      }, [fileName])]);
    }), this.showTrigger && h("li", {
      "class": cardItemClasses,
      "on": {
        "click": this.triggerUpload
      }
    }, [h("div", {
      "class": "".concat(this.classPrefix, "-upload__image-add ").concat(this.classPrefix, "-upload__card-container ").concat(this.classPrefix, "-upload__card-box")
    }, [h(AddIcon), h("p", {
      "class": "".concat(this.classPrefix, "-size-s")
    }, [(_this$locale3 = this.locale) === null || _this$locale3 === void 0 ? void 0 : (_this$locale3$trigger = _this$locale3.triggerUploadText) === null || _this$locale3$trigger === void 0 ? void 0 : _this$locale3$trigger.image])])])])]);
  }
});

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