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

import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { isVNode, defineComponent, toRefs, computed, createVNode, mergeProps } from 'vue';
import { BrowseIcon, DeleteIcon, CheckCircleFilledIcon, ErrorCircleFilledIcon, TimeFilledIcon } from '@ldesign/icons-vue-next';
import { useGlobalIcon } from '../../hooks/useGlobalIcon.js';
import { ImageViewer } from '../../image-viewer/index.js';
import { commonProps } from '../constants.js';
import { Button } from '../../button/index.js';
import useDrag from '../hooks/useDrag.js';
import { abridgeName, returnFileSize } from '../../_common/js/upload/utils.js';
import { Loading } from '../../loading/index.js';
import '../../hooks/index.js';
import { Link } from '../../link/index.js';
import { useTNodeJSX } from '../../hooks/tnode.js';
import '../../hooks/useConfig.js';
import '../../config-provider/useConfig.js';
import 'lodash/cloneDeep';
import 'lodash/isFunction';
import 'lodash/isString';
import '../../config-provider/context.js';
import 'lodash/mergeWith';
import 'lodash/merge';
import 'lodash/isArray';
import '../../_common/js/global-config/default-config.js';
import '../../_common/js/global-config/locale/zh_CN.js';
import '@babel/runtime/helpers/typeof';
import '../../_chunks/dep-512eb181.js';
import 'dayjs';
import '../../_chunks/dep-ac28b67c.js';
import '../../config-provider/type.js';
import '../../utils/withInstall.js';
import '../../image-viewer/image-viewer.js';
import '@babel/runtime/helpers/slicedToArray';
import '../../hooks/useVModel.js';
import 'lodash/kebabCase';
import '../../hooks/useDefaultValue.js';
import '../../image-viewer/props.js';
import '../../image-viewer/base/ImageModalIcon.js';
import 'lodash/camelCase';
import '../../utils/render-tnode.js';
import 'lodash/isEmpty';
import 'lodash/isObject';
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 '../../utils/dom.js';
import '../../utils/easing.js';
import '../../_common/js/utils/set-style.js';
import '../../popup/container.js';
import 'lodash/isUndefined';
import '../../hooks/useResizeObserver.js';
import '../../popup/style';
import '../../popup/type.js';
import '../../tooltip/util.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 '../../hooks/useDestroyOnClose.js';
import '../../_common/js/utils/getScrollbarWidth.js';
import '../../_common/js/utils/helper.js';
import '@babel/runtime/helpers/objectWithoutProperties';
import 'lodash/isNull';
import 'lodash/isNumber';
import '../../hooks/useTeleport.js';
import '../../dialog/stack.js';
import '../../dialog/hooks.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 '../../loading/directive.js';
import '../../loading/plugin.js';
import '../../loading/loading.js';
import '../../loading/props.js';
import '../../loading/icon/gradient.js';
import '../../_common/js/loading/circle-adapter.js';
import '../../loading/style';
import '../../loading/type.js';
import '../../button/style';
import '../../button/type.js';
import '../../dialog/props.js';
import '../../dialog/style';
import '../../dialog/type.js';
import '../../dialog/plugin.js';
import '../../image-viewer/const.js';
import '../../image-viewer/style';
import '../../image-viewer/type.js';
import '../../_common/js/log/log.js';
import '../../hooks/icon.js';
import '../../hooks/slot.js';
import '../../hooks/useCommonClassName.js';
import '../../hooks/useVirtualScroll.js';
import '../../link/link.js';
import '../../link/props.js';
import '../../link/style';
import '../../link/type.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; }
function _isSlot(s) {
  return typeof s === 'function' || Object.prototype.toString.call(s) === '[object Object]' && !isVNode(s);
}
var MultipleFlowList = defineComponent({
  name: "UploadMultipleFlowList",
  props: _objectSpread(_objectSpread({}, 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 = toRefs(props),
      uploading = _toRefs.uploading,
      disabled = _toRefs.disabled,
      displayFiles = _toRefs.displayFiles,
      classPrefix = _toRefs.classPrefix;
    var uploadPrefix = computed(function () {
      return "".concat(classPrefix.value, "-upload");
    });
    var locale = computed(function () {
      return props.locale;
    });
    var renderTNodeJSX = useTNodeJSX();
    var _useGlobalIcon = useGlobalIcon({
        BrowseIcon: BrowseIcon,
        DeleteIcon: DeleteIcon,
        CheckCircleFilledIcon: CheckCircleFilledIcon,
        ErrorCircleFilledIcon: ErrorCircleFilledIcon,
        TimeFilledIcon: TimeFilledIcon
      }),
      BrowseIcon$1 = _useGlobalIcon.BrowseIcon,
      DeleteIcon$1 = _useGlobalIcon.DeleteIcon,
      CheckCircleFilledIcon$1 = _useGlobalIcon.CheckCircleFilledIcon,
      ErrorCircleFilledIcon$1 = _useGlobalIcon.ErrorCircleFilledIcon,
      TimeFilledIcon$1 = _useGlobalIcon.TimeFilledIcon;
    var drag = useDrag(props.dragEvents);
    var uploadText = computed(function () {
      if (uploading.value) return "".concat(locale.value.progress.uploadingText);
      return locale.value.triggerUploadText.normal;
    });
    var innerDragEvents = 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: createVNode(CheckCircleFilledIcon$1, null, null),
        fail: createVNode(ErrorCircleFilledIcon$1, null, null),
        progress: createVNode(Loading, null, null),
        waiting: createVNode(TimeFilledIcon$1, 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 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 ? abridgeName.apply(void 0, [file.name].concat(_toConsumableArray(props.abridgeName))) : file.name;
      return createVNode("li", {
        "class": "".concat(uploadPrefix.value, "__card-item"),
        "key": file.name + index + file.percent + file.status || "0"
      }, [createVNode("div", {
        "class": ["".concat(uploadPrefix.value, "__card-content"), _defineProperty({}, "".concat(classPrefix.value, "-is-bordered"), file.status !== "waiting")]
      }, [["fail", "progress"].includes(file.status) && createVNode("div", {
        "class": "".concat(uploadPrefix.value, "__card-status-wrap ").concat(uploadPrefix.value, "__").concat(props.theme, "-").concat(file.status)
      }, [iconMap[file.status], createVNode("p", null, [textMap[file.status], file.status === "progress" ? " ".concat(file.percent, "%") : ""])]), (["waiting", "success"].includes(file.status) || !file.status && file.url) && createVNode("img", {
        "class": "".concat(uploadPrefix.value, "__card-image"),
        "src": file.url || "//tdesign.gtimg.com/tdesign-default-img.png"
      }, null), createVNode("div", {
        "class": "".concat(uploadPrefix.value, "__card-mask")
      }, [file.url && createVNode("span", {
        "class": "".concat(uploadPrefix.value, "__card-mask-item")
      }, [createVNode(ImageViewer, {
        "images": displayFiles.value.map(function (t) {
          return t.url;
        }),
        "defaultIndex": index,
        "trigger": function trigger(h, _ref3) {
          var open = _ref3.open;
          return createVNode(BrowseIcon$1, {
            "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), createVNode("span", {
        "class": "".concat(uploadPrefix.value, "__card-mask-item-divider")
      }, null)]), !disabled.value && 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
          });
        }
      }, [createVNode(DeleteIcon$1, null, null)])])]), createVNode("p", {
        "class": "".concat(uploadPrefix.value, "__card-name")
      }, [fileName])]);
    };
    var renderStatus = function renderStatus(file) {
      var _getStatusMap2 = getStatusMap(),
        iconMap = _getStatusMap2.iconMap,
        textMap = _getStatusMap2.textMap;
      return createVNode("div", {
        "class": "".concat(uploadPrefix.value, "__flow-status")
      }, [iconMap[file.status], 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 createVNode("td", null, [createVNode(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 ? createVNode("td", {
        "rowspan": displayFiles.value.length,
        "class": "".concat(uploadPrefix.value, "__flow-table__batch-row")
      }, [createVNode(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 createVNode("table", mergeProps({
        "class": "".concat(uploadPrefix.value, "__flow-table")
      }, innerDragEvents.value), [createVNode("thead", null, [createVNode("tr", null, [createVNode("th", null, [(_locale$value$file = locale.value.file) === null || _locale$value$file === void 0 ? void 0 : _locale$value$file.fileNameText]), createVNode("th", {
        "style": {
          minWidth: "120px"
        }
      }, [(_locale$value$file2 = locale.value.file) === null || _locale$value$file2 === void 0 ? void 0 : _locale$value$file2.fileSizeText]), 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 : createVNode("th", null, [(_locale$value$file4 = locale.value.file) === null || _locale$value$file4 === void 0 ? void 0 : _locale$value$file4.fileOperationText])])]), createVNode("tbody", null, [!displayFiles.value.length && createVNode("tr", null, [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 ? abridgeName.apply(void 0, [file.name].concat(_toConsumableArray(props.abridgeName))) : file.name;
        return createVNode("tr", {
          "key": file.name + index + file.percent + file.status || "0"
        }, [createVNode("td", {
          "class": "".concat(uploadPrefix.value, "__file-name")
        }, [file.url ? createVNode(Link, {
          "href": file.url,
          "target": "_blank",
          "hover": "color"
        }, _isSlot(fileName) ? fileName : {
          "default": function _default() {
            return [fileName];
          }
        }) : fileName]), createVNode("td", null, [returnFileSize(file.size)]), 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 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 createVNode("div", {
        "class": "".concat(uploadPrefix.value, "__flow ").concat(uploadPrefix.value, "__flow-").concat(props.theme)
      }, [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 && createVNode("small", {
        "class": "".concat(uploadPrefix.value, "__flow-placeholder ").concat(uploadPrefix.value, "__placeholder")
      }, [props.placeholder])]), props.theme === "image-flow" && createVNode("div", mergeProps({
        "class": cardClassName
      }, innerDragEvents.value), [displayFiles.value.length ? renderImageList() : renderEmpty()]), props.theme === "file-flow" && (displayFiles.value.length ? renderFileList() : createVNode("div", mergeProps({
        "class": cardClassName
      }, innerDragEvents.value), [renderEmpty()])), !props.autoUpload && createVNode("div", {
        "class": "".concat(uploadPrefix.value, "__flow-bottom")
      }, [createVNode(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), createVNode(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)])]);
    };
  }
});

export { MultipleFlowList as default };
//# sourceMappingURL=multiple-flow-list.js.map
