/**
 * ldesign v0.4.2
 * (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 vue = require('vue');
var iconsVueNext = require('@ldesign/icons-vue-next');
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('../../loading/directive.js');
require('../../loading/plugin.js');
require('../../utils/dom.js');
require('../../_chunks/dep-7f0559c3.js');
require('lodash/isString');
require('lodash/isFunction');
require('lodash/isArray');
require('../../utils/easing.js');
require('../../hooks/useConfig.js');
require('../../config-provider/useConfig.js');
require('lodash/cloneDeep');
require('../../config-provider/context.js');
require('lodash/mergeWith');
require('lodash/merge');
require('../../_common/js/global-config/default-config.js');
require('../../_common/js/global-config/locale/zh_CN.js');
require('@babel/runtime/helpers/typeof');
require('dayjs');
require('../../loading/loading.js');
require('@babel/runtime/helpers/slicedToArray');
require('../../utils/render-tnode.js');
require('lodash/isEmpty');
require('lodash/isObject');
require('lodash/camelCase');
require('lodash/kebabCase');
require('../../hooks/useTeleport.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('lodash/isNull');
require('lodash/isUndefined');
require('lodash/isNumber');
require('../../image-viewer/image-viewer.js');
require('../../hooks/tnode.js');
require('../../hooks/useVModel.js');
require('../../hooks/useDefaultValue.js');
require('../../image-viewer/props.js');
require('../../image-viewer/base/ImageModalIcon.js');
require('../../image-viewer/base/ImageViewerUtils.js');
require('../../tooltip/index.js');
require('../../tooltip/tooltip.js');
require('lodash/omit');
require('../../popup/props.js');
require('../../popup/index.js');
require('../../popup/popup.js');
require('@popperjs/core');
require('../../popup/container.js');
require('../../hooks/useResizeObserver.js');
require('../../tooltip/util.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('../../hooks/useDestroyOnClose.js');
require('../../_common/js/utils/getScrollbarWidth.js');
require('../../dialog/stack.js');
require('../../dialog/hooks.js');
require('../../button/index.js');
require('../../button/button.js');
require('../../hooks/useRipple.js');
require('../../utils/set-style.js');
require('../../hooks/useKeepAnimation.js');
require('../../form/hooks.js');
require('../../button/props.js');
require('../../dialog/props.js');
require('../../dialog/plugin.js');
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 = vue.defineComponent({
  name: "UploadImageCard",
  props: _objectSpread(_objectSpread({}, upload_constants.commonProps), {}, {
    multiple: Boolean,
    max: Number,
    disabled: Boolean,
    showUploadProgress: Boolean,
    triggerUpload: Function,
    uploadFiles: Function,
    cancelUpload: Function,
    onPreview: Function
  }),
  setup: function setup(props) {
    var _toRefs = vue.toRefs(props),
      displayFiles = _toRefs.displayFiles,
      classPrefix = _toRefs.classPrefix,
      multiple = _toRefs.multiple,
      max = _toRefs.max;
    var locale = vue.computed(function () {
      return props.locale;
    });
    var _useGlobalIcon = hooks_useGlobalIcon.useGlobalIcon({
        AddIcon: iconsVueNext.AddIcon,
        BrowseIcon: iconsVueNext.BrowseIcon,
        DeleteIcon: iconsVueNext.DeleteIcon,
        ErrorCircleFilledIcon: iconsVueNext.ErrorCircleFilledIcon
      }),
      BrowseIcon = _useGlobalIcon.BrowseIcon,
      DeleteIcon = _useGlobalIcon.DeleteIcon,
      AddIcon = _useGlobalIcon.AddIcon,
      ErrorCircleFilledIcon = _useGlobalIcon.ErrorCircleFilledIcon;
    var showTrigger = vue.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 vue.createVNode("div", {
        "class": "".concat(classPrefix.value, "-upload__card-content ").concat(classPrefix.value, "-upload__card-box")
      }, [vue.createVNode("img", {
        "class": "".concat(classPrefix.value, "-upload__card-image"),
        "src": file.url
      }, null), vue.createVNode("div", {
        "class": "".concat(classPrefix.value, "-upload__card-mask")
      }, [vue.createVNode("span", {
        "class": "".concat(classPrefix.value, "-upload__card-mask-item"),
        "onClick": function onClick(e) {
          return e.stopPropagation();
        }
      }, [vue.createVNode(imageViewer_index.ImageViewer, {
        "images": displayFiles.value.map(function (t) {
          return t.url;
        }),
        "defaultIndex": index,
        "trigger": function trigger(h, _ref) {
          var open = _ref.open;
          return vue.createVNode(BrowseIcon, {
            "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 && vue.createVNode(vue.Fragment, null, [vue.createVNode("span", {
        "class": "".concat(classPrefix.value, "-upload__card-mask-item-divider")
      }, null), vue.createVNode("span", {
        "class": "".concat(classPrefix.value, "-upload__card-mask-item"),
        "onClick": function onClick(e) {
          return e.stopPropagation();
        }
      }, [vue.createVNode(DeleteIcon, {
        "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 vue.createVNode("div", {
        "class": [loadCard, "".concat(classPrefix.value, "-upload__").concat(props.theme, "-").concat(file.status)]
      }, [vue.createVNode(loading_index.Loading, {
        "loading": true,
        "size": "medium"
      }, null), vue.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 vue.createVNode("div", {
        "class": loadCard
      }, [vue.createVNode(ErrorCircleFilledIcon, null, null), vue.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)]), vue.createVNode("div", {
        "class": "".concat(classPrefix.value, "-upload__card-mask")
      }, [vue.createVNode("span", {
        "class": "".concat(classPrefix.value, "-upload__card-mask-item"),
        "onClick": function onClick(e) {
          return e.stopPropagation();
        }
      }, [vue.createVNode(DeleteIcon, {
        "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 vue.createVNode("div", null, [vue.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 ? _common_js_upload_utils.abridgeName.apply(void 0, [file.name].concat(_toConsumableArray__default["default"](props.abridgeName))) : file.name;
        return vue.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), vue.createVNode("div", {
          "class": "".concat(classPrefix.value, "-upload__card-name")
        }, [fileName])]);
      }), showTrigger.value && vue.createVNode("li", {
        "class": cardItemClasses,
        "onClick": props.triggerUpload
      }, [vue.createVNode("div", {
        "class": ["".concat(classPrefix.value, "-upload__image-add"), "".concat(classPrefix.value, "-upload__card-container"), "".concat(classPrefix.value, "-upload__card-box")]
      }, [vue.createVNode(AddIcon, null, null), vue.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])])])])]);
    };
  }
});

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