/**
 * ldesign v0.3.13
 * (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 hooks_useGlobalIcon = require('../../hooks/useGlobalIcon.js');
var imageViewer_index = require('../../image-viewer/index.js');
var upload_constants = require('../constants.js');
var button_index = require('../../button/index.js');
var upload_hooks_useDrag = require('../hooks/useDrag.js');
var _common_js_upload_utils = require('../../_common/js/upload/utils.js');
var loading_index = require('../../loading/index.js');
var link_index = require('../../link/index.js');
var hooks_tnode = require('../../hooks/tnode.js');
require('../../config-provider/useConfig.js');
require('lodash/cloneDeep');
require('lodash/isFunction');
require('lodash/isString');
require('../../config-provider/context.js');
require('lodash/mergeWith');
require('lodash/merge');
require('lodash/isArray');
require('../../_common/js/global-config/default-config.js');
require('../../_common/js/global-config/locale/zh_CN.js');
require('@babel/runtime/helpers/typeof');
require('../../_chunks/dep-f4db2590.js');
require('dayjs');
require('../../utils/withInstall.js');
require('../../image-viewer/image-viewer.js');
require('@babel/runtime/helpers/slicedToArray');
require('../../hooks/useVModel.js');
require('lodash/kebabCase');
require('../../hooks/useDefaultValue.js');
require('../../hooks/useConfig.js');
require('../../image-viewer/props.js');
require('../../image-viewer/base/ImageModalIcon.js');
require('lodash/camelCase');
require('../../utils/render-tnode.js');
require('lodash/isEmpty');
require('lodash/isObject');
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('../../utils/dom.js');
require('../../utils/easing.js');
require('../../_common/js/utils/set-style.js');
require('../../popup/container.js');
require('lodash/isUndefined');
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('../../_common/js/utils/helper.js');
require('@babel/runtime/helpers/objectWithoutProperties');
require('lodash/isNull');
require('lodash/isNumber');
require('../../hooks/useTeleport.js');
require('../../dialog/stack.js');
require('../../dialog/hooks.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('../../loading/directive.js');
require('../../loading/plugin.js');
require('../../loading/loading.js');
require('../../loading/props.js');
require('../../loading/icon/gradient.js');
require('../../_common/js/loading/circle-adapter.js');
require('../../dialog/props.js');
require('../../dialog/plugin.js');
require('../../image-viewer/const.js');
require('../../_common/js/log/log.js');
require('../../link/link.js');
require('../../link/props.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; }
function _isSlot(s) {
  return typeof s === 'function' || Object.prototype.toString.call(s) === '[object Object]' && !vue.isVNode(s);
}
var MultipleFlowList = vue.defineComponent({
  name: "UploadMultipleFlowList",
  props: _objectSpread(_objectSpread({}, upload_constants.commonProps), {}, {
    uploadFiles: Function,
    cancelUpload: Function,
    dragEvents: Object,
    disabled: Boolean,
    isBatchUpload: Boolean,
    draggable: Boolean,
    onPreview: Function
  }),
  setup: function setup(props, _ref) {
    var slots = _ref.slots;
    var _toRefs = vue.toRefs(props),
      uploading = _toRefs.uploading,
      disabled = _toRefs.disabled,
      displayFiles = _toRefs.displayFiles,
      classPrefix = _toRefs.classPrefix;
    var uploadPrefix = vue.computed(function () {
      return "".concat(classPrefix.value, "-upload");
    });
    var locale = vue.computed(function () {
      return props.locale;
    });
    var renderTNodeJSX = hooks_tnode.useTNodeJSX();
    var _useGlobalIcon = hooks_useGlobalIcon.useGlobalIcon({
        BrowseIcon: iconsVueNext.BrowseIcon,
        DeleteIcon: iconsVueNext.DeleteIcon,
        CheckCircleFilledIcon: iconsVueNext.CheckCircleFilledIcon,
        ErrorCircleFilledIcon: iconsVueNext.ErrorCircleFilledIcon,
        TimeFilledIcon: iconsVueNext.TimeFilledIcon
      }),
      BrowseIcon = _useGlobalIcon.BrowseIcon,
      DeleteIcon = _useGlobalIcon.DeleteIcon,
      CheckCircleFilledIcon = _useGlobalIcon.CheckCircleFilledIcon,
      ErrorCircleFilledIcon = _useGlobalIcon.ErrorCircleFilledIcon,
      TimeFilledIcon = _useGlobalIcon.TimeFilledIcon;
    var drag = upload_hooks_useDrag["default"](props.dragEvents);
    var uploadText = vue.computed(function () {
      if (uploading.value) return "".concat(locale.value.progress.uploadingText);
      return locale.value.triggerUploadText.normal;
    });
    var innerDragEvents = vue.computed(function () {
      var draggable = props.draggable === void 0 ? true : props.draggable;
      return draggable ? {
        onDrop: drag.handleDrop,
        onDragenter: drag.handleDragenter,
        onDragover: drag.handleDragover,
        onDragleave: drag.handleDragleave
      } : {};
    });
    var getStatusMap = function getStatusMap() {
      var iconMap = {
        success: vue.createVNode(CheckCircleFilledIcon, null, null),
        fail: vue.createVNode(ErrorCircleFilledIcon, null, null),
        progress: vue.createVNode(loading_index.Loading, null, null),
        waiting: vue.createVNode(TimeFilledIcon, null, null)
      };
      var progress = locale.value.progress;
      var textMap = {
        success: progress === null || progress === void 0 ? void 0 : progress.successText,
        fail: progress === null || progress === void 0 ? void 0 : progress.failText,
        progress: progress === null || progress === void 0 ? void 0 : progress.uploadingText,
        waiting: progress === null || progress === void 0 ? void 0 : progress.waitingText
      };
      return {
        iconMap: iconMap,
        textMap: textMap
      };
    };
    var renderEmpty = function renderEmpty() {
      return vue.createVNode("div", {
        "class": "".concat(uploadPrefix.value, "__flow-empty")
      }, [drag.dragActive.value ? locale.value.dragger.dragDropText : locale.value.dragger.clickAndDragText]);
    };
    var renderImgItem = function renderImgItem(file, index) {
      var _getStatusMap = getStatusMap(),
        iconMap = _getStatusMap.iconMap,
        textMap = _getStatusMap.textMap;
      var fileName = props.abridgeName && file.name ? _common_js_upload_utils.abridgeName.apply(void 0, [file.name].concat(_toConsumableArray__default["default"](props.abridgeName))) : file.name;
      return vue.createVNode("li", {
        "class": "".concat(uploadPrefix.value, "__card-item"),
        "key": file.name + index + file.percent + file.status || "0"
      }, [vue.createVNode("div", {
        "class": ["".concat(uploadPrefix.value, "__card-content"), _defineProperty__default["default"]({}, "".concat(classPrefix.value, "-is-bordered"), file.status !== "waiting")]
      }, [["fail", "progress"].includes(file.status) && vue.createVNode("div", {
        "class": "".concat(uploadPrefix.value, "__card-status-wrap ").concat(uploadPrefix.value, "__").concat(props.theme, "-").concat(file.status)
      }, [iconMap[file.status], vue.createVNode("p", null, [textMap[file.status], file.status === "progress" ? " ".concat(file.percent, "%") : ""])]), (["waiting", "success"].includes(file.status) || !file.status && file.url) && vue.createVNode("img", {
        "class": "".concat(uploadPrefix.value, "__card-image"),
        "src": file.url || "//tdesign.gtimg.com/tdesign-default-img.png"
      }, null), vue.createVNode("div", {
        "class": "".concat(uploadPrefix.value, "__card-mask")
      }, [file.url && vue.createVNode("span", {
        "class": "".concat(uploadPrefix.value, "__card-mask-item")
      }, [vue.createVNode(imageViewer_index.ImageViewer, {
        "images": displayFiles.value.map(function (t) {
          return t.url;
        }),
        "defaultIndex": index,
        "trigger": function trigger(h, _ref3) {
          var open = _ref3.open;
          return vue.createVNode(BrowseIcon, {
            "onClick": function onClick(_ref4) {
              var _props$onPreview;
              var e = _ref4.e;
              open();
              (_props$onPreview = props.onPreview) === null || _props$onPreview === void 0 ? void 0 : _props$onPreview.call(props, {
                file: file,
                index: index,
                e: e
              });
            }
          }, null);
        }
      }, null), vue.createVNode("span", {
        "class": "".concat(uploadPrefix.value, "__card-mask-item-divider")
      }, null)]), !disabled.value && vue.createVNode("span", {
        "class": "".concat(uploadPrefix.value, "__card-mask-item ").concat(uploadPrefix.value, "__delete"),
        "onClick": function onClick(e) {
          return props.onRemove({
            e: e,
            index: index,
            file: file
          });
        }
      }, [vue.createVNode(DeleteIcon, null, null)])])]), vue.createVNode("p", {
        "class": "".concat(uploadPrefix.value, "__card-name")
      }, [fileName])]);
    };
    var renderStatus = function renderStatus(file) {
      var _getStatusMap2 = getStatusMap(),
        iconMap = _getStatusMap2.iconMap,
        textMap = _getStatusMap2.textMap;
      return vue.createVNode("div", {
        "class": "".concat(uploadPrefix.value, "__flow-status")
      }, [iconMap[file.status], vue.createVNode("span", {
        "class": "".concat(uploadPrefix.value, "__").concat(props.theme, "-").concat(file.status)
      }, [textMap[file.status], props.showUploadProgress && file.status === "progress" ? " ".concat(file.percent || 0, "%") : ""])]);
    };
    var renderNormalActionCol = function renderNormalActionCol(file, index) {
      var _locale$value, _locale$value$trigger;
      return vue.createVNode("td", null, [vue.createVNode(button_index.Button, {
        "theme": "primary",
        "variant": "text",
        "content": (_locale$value = locale.value) === null || _locale$value === void 0 ? void 0 : (_locale$value$trigger = _locale$value.triggerUploadText) === null || _locale$value$trigger === void 0 ? void 0 : _locale$value$trigger["delete"],
        "class": "".concat(uploadPrefix.value, "__delete"),
        "onClick": function onClick(e) {
          return props.onRemove({
            e: e,
            index: index,
            file: file
          });
        }
      }, null)]);
    };
    var renderBatchActionCol = function renderBatchActionCol(index) {
      var _locale$value2, _locale$value2$trigge;
      return index === 0 ? vue.createVNode("td", {
        "rowspan": displayFiles.value.length,
        "class": "".concat(uploadPrefix.value, "__flow-table__batch-row")
      }, [vue.createVNode(button_index.Button, {
        "theme": "primary",
        "variant": "text",
        "content": (_locale$value2 = locale.value) === null || _locale$value2 === void 0 ? void 0 : (_locale$value2$trigge = _locale$value2.triggerUploadText) === null || _locale$value2$trigge === void 0 ? void 0 : _locale$value2$trigge["delete"],
        "class": "".concat(uploadPrefix.value, "__delete"),
        "onClick": function onClick(e) {
          return props.onRemove({
            e: e,
            index: -1,
            file: void 0
          });
        }
      }, null)]) : null;
    };
    var renderFileList = function renderFileList() {
      var _locale$value$file, _locale$value$file2, _locale$value$file3, _locale$value$file4;
      var customList = renderTNodeJSX("fileListDisplay", {
        params: {
          files: props.displayFiles,
          dragEvents: innerDragEvents.value
        }
      });
      if (customList || props.fileListDisplay) return customList;
      return vue.createVNode("table", vue.mergeProps({
        "class": "".concat(uploadPrefix.value, "__flow-table")
      }, innerDragEvents.value), [vue.createVNode("thead", null, [vue.createVNode("tr", null, [vue.createVNode("th", null, [(_locale$value$file = locale.value.file) === null || _locale$value$file === void 0 ? void 0 : _locale$value$file.fileNameText]), vue.createVNode("th", {
        "style": {
          minWidth: "120px"
        }
      }, [(_locale$value$file2 = locale.value.file) === null || _locale$value$file2 === void 0 ? void 0 : _locale$value$file2.fileSizeText]), vue.createVNode("th", {
        "style": {
          minWidth: "120px"
        }
      }, [(_locale$value$file3 = locale.value.file) === null || _locale$value$file3 === void 0 ? void 0 : _locale$value$file3.fileStatusText]), disabled.value ? null : vue.createVNode("th", null, [(_locale$value$file4 = locale.value.file) === null || _locale$value$file4 === void 0 ? void 0 : _locale$value$file4.fileOperationText])])]), vue.createVNode("tbody", null, [!displayFiles.value.length && vue.createVNode("tr", null, [vue.createVNode("td", {
        "colspan": 4
      }, [renderEmpty()])]), displayFiles.value.map(function (file, index) {
        var _props$abridgeName;
        var showBatchUploadAction = props.isBatchUpload;
        var deleteNode = showBatchUploadAction && displayFiles.value.every(function (item) {
          return item.status === "success" || !item.status;
        }) ? renderBatchActionCol(index) : renderNormalActionCol(file, index);
        var fileName = (_props$abridgeName = props.abridgeName) !== null && _props$abridgeName !== void 0 && _props$abridgeName.length ? _common_js_upload_utils.abridgeName.apply(void 0, [file.name].concat(_toConsumableArray__default["default"](props.abridgeName))) : file.name;
        return vue.createVNode("tr", {
          "key": file.name + index + file.percent + file.status || "0"
        }, [vue.createVNode("td", {
          "class": "".concat(uploadPrefix.value, "__file-name")
        }, [file.url ? vue.createVNode(link_index.Link, {
          "href": file.url,
          "target": "_blank",
          "hover": "color"
        }, _isSlot(fileName) ? fileName : {
          "default": function _default() {
            return [fileName];
          }
        }) : fileName]), vue.createVNode("td", null, [_common_js_upload_utils.returnFileSize(file.size)]), vue.createVNode("td", null, [renderStatus(file)]), disabled.value ? null : deleteNode]);
      })])]);
    };
    var renderImageList = function renderImageList() {
      var customList = renderTNodeJSX("fileListDisplay", {
        params: {
          files: props.displayFiles,
          dragEvents: innerDragEvents.value
        }
      });
      if (customList || props.fileListDisplay) return customList;
      return vue.createVNode("ul", {
        "class": "".concat(uploadPrefix.value, "__card clearfix")
      }, [props.displayFiles.map(function (file, index) {
        return renderImgItem(file, index);
      })]);
    };
    return function () {
      var _slots$default, _locale$value3;
      var cardClassName = "".concat(uploadPrefix.value, "__flow-card-area");
      return vue.createVNode("div", {
        "class": "".concat(uploadPrefix.value, "__flow ").concat(uploadPrefix.value, "__flow-").concat(props.theme)
      }, [vue.createVNode("div", {
        "class": "".concat(uploadPrefix.value, "__flow-op")
      }, [(_slots$default = slots["default"]) === null || _slots$default === void 0 ? void 0 : _slots$default.call(slots), props.placeholder && vue.createVNode("small", {
        "class": "".concat(uploadPrefix.value, "__flow-placeholder ").concat(uploadPrefix.value, "__placeholder")
      }, [props.placeholder])]), props.theme === "image-flow" && vue.createVNode("div", vue.mergeProps({
        "class": cardClassName
      }, innerDragEvents.value), [displayFiles.value.length ? renderImageList() : renderEmpty()]), props.theme === "file-flow" && (displayFiles.value.length ? renderFileList() : vue.createVNode("div", vue.mergeProps({
        "class": cardClassName
      }, innerDragEvents.value), [renderEmpty()])), !props.autoUpload && vue.createVNode("div", {
        "class": "".concat(uploadPrefix.value, "__flow-bottom")
      }, [vue.createVNode(button_index.Button, {
        "theme": "default",
        "disabled": disabled.value || !uploading.value,
        "content": (_locale$value3 = locale.value) === null || _locale$value3 === void 0 ? void 0 : _locale$value3.cancelUploadText,
        "class": "".concat(uploadPrefix.value, "__cancel"),
        "onClick": function onClick(e) {
          var _props$cancelUpload;
          return (_props$cancelUpload = props.cancelUpload) === null || _props$cancelUpload === void 0 ? void 0 : _props$cancelUpload.call(props, {
            e: e
          });
        }
      }, null), vue.createVNode(button_index.Button, {
        "disabled": disabled.value || uploading.value || !displayFiles.value.length,
        "theme": "primary",
        "loading": uploading.value,
        "class": "".concat(uploadPrefix.value, "__continue"),
        "content": uploadText.value,
        "onClick": function onClick() {
          var _props$uploadFiles;
          return (_props$uploadFiles = props.uploadFiles) === null || _props$uploadFiles === void 0 ? void 0 : _props$uploadFiles.call(props);
        }
      }, null)])]);
    };
  }
});

exports["default"] = MultipleFlowList;
//# sourceMappingURL=multiple-flow-list.js.map
