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

import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { defineComponent, toRefs, computed } from '@vue/composition-api';
import { AddIcon, BrowseIcon, DeleteIcon, ErrorCircleFilledIcon } from '@ldesign/icons-vue';
import { Loading } from '../../loading/index.js';
import { useGlobalIcon } from '../../hooks/useGlobalIcon.js';
import { ImageViewer } from '../../image-viewer/index.js';
import { commonProps } from '../constants.js';
import { abridgeName } from '../../_common/js/upload/utils.js';
import '../../utils/withInstall.js';
import 'vue';
import 'lodash/capitalize';
import '../../loading/directive.js';
import 'lodash/isObject';
import 'lodash/mapKeys';
import 'lodash/isEqual';
import '../../loading/plugin.js';
import '../../config.js';
import '../../utils/dom.js';
import 'raf';
import 'lodash/isString';
import '../../utils/easing.js';
import '../../loading/loading.js';
import '../../utils/render-tnode.js';
import '@babel/runtime/helpers/typeof';
import 'lodash/camelCase';
import 'lodash/kebabCase';
import '../../utils/transfer-dom.js';
import '../../config-provider/config-receiver.js';
import 'lodash/mergeWith';
import '../../config-provider/context.js';
import 'lodash/merge';
import '../../_common/js/global-config/default-config.js';
import '../../_common/js/global-config/locale/zh_CN.js';
import '../../_chunks/dep-be599ec8.js';
import 'dayjs';
import '../../_chunks/dep-67ff4010.js';
import '../../config-provider/type.js';
import '../../utils/mixins.js';
import '../../loading/props.js';
import '../../loading/icon/gradient.js';
import '../../_common/js/loading/circle-adapter.js';
import '../../_common/js/utils/set-style.js';
import '../../_common/js/utils/helper.js';
import '@babel/runtime/helpers/objectWithoutProperties';
import '@babel/runtime/helpers/slicedToArray';
import 'lodash/isNull';
import 'lodash/isUndefined';
import 'lodash/isNumber';
import 'lodash/isArray';
import '../../loading/style';
import '../../loading/type.js';
import '../../hooks/useConfig.js';
import '../../config-provider/useConfig.js';
import '../../image-viewer/image-viewer.js';
import '../../hooks/useVModel.js';
import '../../hooks/useDefaultValue.js';
import '../../utils/helper.js';
import '../../image-viewer/props.js';
import '../../image-viewer/base/Container.js';
import '../../image-viewer/base/ImageModalIcon.js';
import '../../hooks/tnode.js';
import 'lodash/isEmpty';
import 'lodash/isFunction';
import '../../hooks/render-tnode.js';
import '../../image-viewer/base/ImageViewerUtils.js';
import '../../tooltip/index.js';
import '../../utils/map-props.js';
import '../../tooltip/tooltip.js';
import '../../_chunks/dep-c89aafbb.js';
import '../../popup/props.js';
import '../../popup/popup.js';
import '@popperjs/core';
import '../../utils/event.js';
import '../../popup/container.js';
import '../../popup/utils.js';
import '../../popup/trigger.js';
import '../../tooltip/props.js';
import '../../tooltip/style';
import '../../tooltip/type.js';
import '../../image-viewer/utils.js';
import '../../image-viewer/base/ImageItem.js';
import '../../image-viewer/hooks.js';
import '../../image-viewer/base/ImageViewerModal.js';
import '../../dialog/index.js';
import '../../dialog/dialog.js';
import 'lodash/throttle';
import '../../button/index.js';
import '../../button/button.js';
import '../../utils/ripple.js';
import '../../button/props.js';
import '../../button/style';
import '../../button/type.js';
import '../../hooks/useDestroyOnClose.js';
import '../../_common/js/utils/getScrollbarWidth.js';
import '../../dialog/stack.js';
import '../../dialog/props.js';
import '../../dialog/actions.js';
import '../../dialog/style';
import '../../dialog/type.js';
import '../../dialog/plugin.js';
import '../../config-provider/config-provider.js';
import 'lodash/cloneDeep';
import '../../image-viewer/const.js';
import '../../image-viewer/style';
import '../../image-viewer/type.js';
import '../../_common/js/log/log.js';

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(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 = defineComponent({
  name: "UploadImageCard",
  props: _objectSpread(_objectSpread({}, commonProps), {}, {
    multiple: Boolean,
    max: Number,
    disabled: Boolean,
    showUploadProgress: Boolean,
    triggerUpload: Function,
    uploadFiles: Function,
    cancelUpload: Function
  }),
  setup: function setup(props) {
    var _toRefs = toRefs(props),
      displayFiles = _toRefs.displayFiles,
      multiple = _toRefs.multiple,
      max = _toRefs.max;
    var icons = useGlobalIcon({
      AddIcon: AddIcon,
      BrowseIcon: BrowseIcon,
      DeleteIcon: DeleteIcon,
      ErrorCircleFilledIcon: ErrorCircleFilledIcon
    });
    var showTrigger = 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, {
        "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, {
        "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 ? abridgeName.apply(void 0, [file.name].concat(_toConsumableArray(_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])])])])]);
  }
});

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