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

import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { defineComponent, toRefs, computed, createVNode, Fragment } from 'vue';
import { AddIcon, BrowseIcon, DeleteIcon, ErrorCircleFilledIcon } from '@ldesign/icons-vue-next';
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 '../../loading/directive.js';
import '../../loading/plugin.js';
import '../../utils/dom.js';
import '../../_chunks/dep-c9c789a8.js';
import 'lodash/isString';
import 'lodash/isFunction';
import 'lodash/isArray';
import '../../utils/easing.js';
import '../../hooks/useConfig.js';
import '../../config-provider/useConfig.js';
import 'lodash/cloneDeep';
import '../../config-provider/context.js';
import 'lodash/mergeWith';
import 'lodash/merge';
import '../../_common/js/global-config/default-config.js';
import '../../_common/js/global-config/locale/zh_CN.js';
import '@babel/runtime/helpers/typeof';
import 'dayjs';
import '../../loading/loading.js';
import '@babel/runtime/helpers/slicedToArray';
import '../../utils/render-tnode.js';
import 'lodash/isEmpty';
import 'lodash/isObject';
import 'lodash/camelCase';
import 'lodash/kebabCase';
import '../../hooks/useTeleport.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 'lodash/isNull';
import 'lodash/isUndefined';
import 'lodash/isNumber';
import '../../image-viewer/image-viewer.js';
import '../../hooks/tnode.js';
import '../../hooks/useVModel.js';
import '../../hooks/useDefaultValue.js';
import '../../image-viewer/props.js';
import '../../image-viewer/base/ImageModalIcon.js';
import '../../image-viewer/base/ImageViewerUtils.js';
import '../../tooltip/index.js';
import '../../tooltip/tooltip.js';
import 'lodash/omit';
import '../../popup/props.js';
import '../../popup/index.js';
import '../../popup/popup.js';
import '@popperjs/core';
import '../../popup/container.js';
import '../../hooks/useResizeObserver.js';
import '../../tooltip/util.js';
import '../../tooltip/props.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 '../../hooks/useDestroyOnClose.js';
import '../../_common/js/utils/getScrollbarWidth.js';
import '../../dialog/stack.js';
import '../../dialog/hooks.js';
import '../../button/index.js';
import '../../button/button.js';
import '../../hooks/useRipple.js';
import '../../utils/set-style.js';
import '../../hooks/useKeepAnimation.js';
import '../../form/hooks.js';
import '../../button/props.js';
import '../../dialog/props.js';
import '../../dialog/plugin.js';
import '../../image-viewer/const.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,
    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.js.map
