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

import { _ as _toConsumableArray } from '../../_chunks/dep-e091cfd9.mjs';
import { _ as _defineProperty } from '../../_chunks/dep-eb20e23f.mjs';
import { defineComponent, toRefs, computed, createVNode, Fragment } from 'vue';
import { AddIcon, BrowseIcon, DeleteIcon, ErrorCircleFilledIcon } from '@ldesign/icons-vue-next';
import { Loading } from '../../loading/index.mjs';
import { useGlobalIcon } from '../../hooks/useGlobalIcon.mjs';
import { ImageViewer } from '../../image-viewer/index.mjs';
import { commonProps } from '../constants.mjs';
import { abridgeName } from '../../_common/js/upload/utils.mjs';
import '../../_chunks/dep-cfcedf47.mjs';
import '../../_chunks/dep-b4041200.mjs';
import '../../utils/withInstall.mjs';
import '../../loading/directive.mjs';
import '../../loading/plugin.mjs';
import '../../utils/dom.mjs';
import '../../_chunks/dep-a0b4a044.mjs';
import '../../_chunks/dep-1cf2b129.mjs';
import '../../_chunks/dep-c959a6fb.mjs';
import '../../_chunks/dep-e3b14d70.mjs';
import '../../_chunks/dep-66d6733b.mjs';
import '../../_chunks/dep-c31e1d9e.mjs';
import '../../_chunks/dep-6b22dd27.mjs';
import '../../_chunks/dep-0f0c89ff.mjs';
import '../../utils/easing.mjs';
import '../../hooks/useConfig.mjs';
import '../../config-provider/useConfig.mjs';
import '../../_chunks/dep-44417261.mjs';
import '../../_chunks/dep-bf74f1c2.mjs';
import '../../_chunks/dep-79821ff2.mjs';
import '../../_chunks/dep-0bfbf721.mjs';
import '../../_chunks/dep-39cc276d.mjs';
import '../../_chunks/dep-8f777748.mjs';
import '../../_chunks/dep-ae357f26.mjs';
import '../../_chunks/dep-352691c2.mjs';
import '../../_chunks/dep-2cfd5b3a.mjs';
import '../../_chunks/dep-05fa17c9.mjs';
import '../../_chunks/dep-a9c8a5d5.mjs';
import '../../_chunks/dep-10085c61.mjs';
import '../../_chunks/dep-1b058de3.mjs';
import '../../_chunks/dep-c852a61a.mjs';
import '../../_chunks/dep-92e7085e.mjs';
import '../../_chunks/dep-44f056cd.mjs';
import '../../_chunks/dep-23a0f453.mjs';
import '../../_chunks/dep-99920870.mjs';
import '../../_chunks/dep-c7e9ce16.mjs';
import '../../_chunks/dep-3afa94cf.mjs';
import '../../_chunks/dep-ba3c0b2e.mjs';
import '../../_chunks/dep-ee57d235.mjs';
import '../../_common/js/global-config/default-config.mjs';
import '../../_common/js/global-config/locale/zh_CN.mjs';
import '../../_chunks/dep-6b4aa943.mjs';
import '../../_chunks/dep-d52291a9.mjs';
import '../../config-provider/type.mjs';
import '../../loading/loading.mjs';
import '../../_chunks/dep-55846619.mjs';
import '../../utils/render-tnode.mjs';
import '../../_chunks/dep-bd03960e.mjs';
import '../../_chunks/dep-f6649a46.mjs';
import '../../_chunks/dep-37ba476d.mjs';
import '../../_chunks/dep-be27d184.mjs';
import '../../_chunks/dep-1fe0ad42.mjs';
import '../../_chunks/dep-d54f2690.mjs';
import '../../_chunks/dep-59c8420d.mjs';
import '../../_chunks/dep-74848b92.mjs';
import '../../_chunks/dep-c4e1a112.mjs';
import '../../hooks/useTeleport.mjs';
import '../../loading/props.mjs';
import '../../loading/icon/gradient.mjs';
import '../../_common/js/loading/circle-adapter.mjs';
import '../../_common/js/utils/set-style.mjs';
import '../../_common/js/utils/helper.mjs';
import '../../_chunks/dep-b6a73f93.mjs';
import '../../_chunks/dep-6f89b77e.mjs';
import '../../_chunks/dep-30451c48.mjs';
import '../../_chunks/dep-6eea369f.mjs';
import '../../loading/style/css.mjs';
import '../../loading/type.mjs';
import '../../image-viewer/image-viewer.mjs';
import '../../hooks/tnode.mjs';
import '../../hooks/useVModel.mjs';
import '../../hooks/useDefaultValue.mjs';
import '../../image-viewer/props.mjs';
import '../../image-viewer/base/ImageModalIcon.mjs';
import '../../image-viewer/base/ImageViewerUtils.mjs';
import '../../tooltip/index.mjs';
import '../../tooltip/tooltip.mjs';
import '../../_chunks/dep-b2af48ba.mjs';
import '../../_chunks/dep-7acc11cb.mjs';
import '../../_chunks/dep-774ac2d0.mjs';
import '../../popup/props.mjs';
import '../../popup/index.mjs';
import '../../popup/popup.mjs';
import '@popperjs/core';
import '../../hooks/index.mjs';
import '../../hooks/icon.mjs';
import '../../hooks/slot.mjs';
import '../../hooks/useCommonClassName.mjs';
import '../../hooks/useDestroyOnClose.mjs';
import '../../hooks/useKeepAnimation.mjs';
import '../../hooks/useRipple.mjs';
import '../../utils/set-style.mjs';
import '../../hooks/useVirtualScroll.mjs';
import '../../popup/container.mjs';
import '../../hooks/useResizeObserver.mjs';
import '../../popup/style/css.mjs';
import '../../popup/type.mjs';
import '../../tooltip/util.mjs';
import '../../tooltip/props.mjs';
import '../../tooltip/style/css.mjs';
import '../../tooltip/type.mjs';
import '../../image-viewer/utils.mjs';
import '../../image-viewer/base/ImageItem.mjs';
import '../../image-viewer/hooks.mjs';
import '../../image-viewer/base/ImageViewerModal.mjs';
import '../../dialog/index.mjs';
import '../../dialog/dialog.mjs';
import '../../_common/js/utils/getScrollbarWidth.mjs';
import '../../dialog/stack.mjs';
import '../../dialog/hooks.mjs';
import '../../button/index.mjs';
import '../../button/button.mjs';
import '../../form/hooks.mjs';
import '../../button/props.mjs';
import '../../button/style/css.mjs';
import '../../button/type.mjs';
import '../../dialog/props.mjs';
import '../../dialog/style/css.mjs';
import '../../dialog/type.mjs';
import '../../dialog/plugin.mjs';
import '../../image-viewer/const.mjs';
import '../../image-viewer/style/css.mjs';
import '../../image-viewer/type.mjs';
import '../../_common/js/log/log.mjs';

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,
    onPreview: Function
  }),
  setup: function setup(props) {
    var _toRefs = toRefs(props),
      displayFiles = _toRefs.displayFiles,
      classPrefix = _toRefs.classPrefix,
      multiple = _toRefs.multiple,
      max = _toRefs.max;
    var locale = computed(function () {
      return props.locale;
    });
    var _useGlobalIcon = useGlobalIcon({
        AddIcon: AddIcon,
        BrowseIcon: BrowseIcon,
        DeleteIcon: DeleteIcon,
        ErrorCircleFilledIcon: ErrorCircleFilledIcon
      }),
      BrowseIcon$1 = _useGlobalIcon.BrowseIcon,
      DeleteIcon$1 = _useGlobalIcon.DeleteIcon,
      AddIcon$1 = _useGlobalIcon.AddIcon,
      ErrorCircleFilledIcon$1 = _useGlobalIcon.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]);
    });
    var renderMainContent = function renderMainContent(file, index) {
      return createVNode("div", {
        "class": "".concat(classPrefix.value, "-upload__card-content ").concat(classPrefix.value, "-upload__card-box")
      }, [createVNode("img", {
        "class": "".concat(classPrefix.value, "-upload__card-image"),
        "src": file.url
      }, null), createVNode("div", {
        "class": "".concat(classPrefix.value, "-upload__card-mask")
      }, [createVNode("span", {
        "class": "".concat(classPrefix.value, "-upload__card-mask-item"),
        "onClick": function onClick(e) {
          return e.stopPropagation();
        }
      }, [createVNode(ImageViewer, {
        "images": displayFiles.value.map(function (t) {
          return t.url;
        }),
        "defaultIndex": index,
        "trigger": function trigger(h, _ref) {
          var open = _ref.open;
          return createVNode(BrowseIcon$1, {
            "onClick": function onClick(_ref2) {
              var _props$onPreview;
              var e = _ref2.e;
              (_props$onPreview = props.onPreview) === null || _props$onPreview === void 0 ? void 0 : _props$onPreview.call(props, {
                file: file,
                index: index,
                e: e
              });
              open();
            }
          }, null);
        }
      }, null)]), !props.disabled && createVNode(Fragment, null, [createVNode("span", {
        "class": "".concat(classPrefix.value, "-upload__card-mask-item-divider")
      }, null), createVNode("span", {
        "class": "".concat(classPrefix.value, "-upload__card-mask-item"),
        "onClick": function onClick(e) {
          return e.stopPropagation();
        }
      }, [createVNode(DeleteIcon$1, {
        "onClick": function onClick(_ref3) {
          var _props$onRemove;
          var e = _ref3.e;
          return props === null || props === void 0 ? void 0 : (_props$onRemove = props.onRemove) === null || _props$onRemove === void 0 ? void 0 : _props$onRemove.call(props, {
            e: e,
            file: file,
            index: index
          });
        }
      }, null)])])])]);
    };
    var renderProgressFile = function renderProgressFile(file, loadCard) {
      var _locale$value, _locale$value$progres;
      return createVNode("div", {
        "class": [loadCard, "".concat(classPrefix.value, "-upload__").concat(props.theme, "-").concat(file.status)]
      }, [createVNode(Loading, {
        "loading": true,
        "size": "medium"
      }, null), createVNode("p", null, [(_locale$value = locale.value) === null || _locale$value === void 0 ? void 0 : (_locale$value$progres = _locale$value.progress) === null || _locale$value$progres === void 0 ? void 0 : _locale$value$progres.uploadingText, props.showUploadProgress ? " ".concat(file.percent, "%") : ""])]);
    };
    var renderFailFile = function renderFailFile(file, index, loadCard) {
      var _file$response, _locale$value2, _locale$value2$progre;
      return createVNode("div", {
        "class": loadCard
      }, [createVNode(ErrorCircleFilledIcon$1, null, null), createVNode("p", null, [((_file$response = file.response) === null || _file$response === void 0 ? void 0 : _file$response.error) || ((_locale$value2 = locale.value) === null || _locale$value2 === void 0 ? void 0 : (_locale$value2$progre = _locale$value2.progress) === null || _locale$value2$progre === void 0 ? void 0 : _locale$value2$progre.failText)]), createVNode("div", {
        "class": "".concat(classPrefix.value, "-upload__card-mask")
      }, [createVNode("span", {
        "class": "".concat(classPrefix.value, "-upload__card-mask-item"),
        "onClick": function onClick(e) {
          return e.stopPropagation();
        }
      }, [createVNode(DeleteIcon$1, {
        "onClick": function onClick(_ref4) {
          var _props$onRemove2;
          var e = _ref4.e;
          return props === null || props === void 0 ? void 0 : (_props$onRemove2 = props.onRemove) === null || _props$onRemove2 === void 0 ? void 0 : _props$onRemove2.call(props, {
            e: e,
            file: file,
            index: index
          });
        }
      }, null)])])]);
    };
    return function () {
      var _displayFiles$value2, _locale$value3, _locale$value3$trigge;
      var cardItemClasses = "".concat(classPrefix.value, "-upload__card-item ").concat(classPrefix.value, "-is-background");
      return createVNode("div", null, [createVNode("ul", {
        "class": "".concat(classPrefix.value, "-upload__card")
      }, [(_displayFiles$value2 = displayFiles.value) === null || _displayFiles$value2 === void 0 ? void 0 : _displayFiles$value2.map(function (file, index) {
        var loadCard = "".concat(classPrefix.value, "-upload__card-container ").concat(classPrefix.value, "-upload__card-box");
        var fileName = props.abridgeName ? abridgeName.apply(void 0, [file.name].concat(_toConsumableArray(props.abridgeName))) : file.name;
        return createVNode("li", {
          "class": cardItemClasses,
          "key": index
        }, [file.status === "progress" && renderProgressFile(file, loadCard), file.status === "fail" && renderFailFile(file, index, loadCard), !["progress", "fail"].includes(file.status) && file.url && renderMainContent(file, index), createVNode("div", {
          "class": "".concat(classPrefix.value, "-upload__card-name")
        }, [fileName])]);
      }), showTrigger.value && createVNode("li", {
        "class": cardItemClasses,
        "onClick": props.triggerUpload
      }, [createVNode("div", {
        "class": ["".concat(classPrefix.value, "-upload__image-add"), "".concat(classPrefix.value, "-upload__card-container"), "".concat(classPrefix.value, "-upload__card-box")]
      }, [createVNode(AddIcon$1, null, null), createVNode("p", {
        "class": "".concat(classPrefix.value, "-size-s")
      }, [(_locale$value3 = locale.value) === null || _locale$value3 === void 0 ? void 0 : (_locale$value3$trigge = _locale$value3.triggerUploadText) === null || _locale$value3$trigge === void 0 ? void 0 : _locale$value3$trigge.image])])])])]);
    };
  }
});

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