/**
 * 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, ref, createVNode, h } from 'vue';
import { CheckCircleFilledIcon, ErrorCircleFilledIcon } from '@ldesign/icons-vue-next';
import { abridgeName, getFileSizeText } from '../../_common/js/upload/utils.mjs';
import { Button } from '../../button/index.mjs';
import { commonProps } from '../constants.mjs';
import useCommonClassName from '../../hooks/useCommonClassName.mjs';
import { Loading } from '../../loading/index.mjs';
import useDrag from '../hooks/useDrag.mjs';
import { useGlobalIcon } from '../../hooks/useGlobalIcon.mjs';
import { ImageViewer } from '../../image-viewer/index.mjs';
import '../../hooks/index.mjs';
import { useTNodeJSX } from '../../hooks/tnode.mjs';
import '../../_chunks/dep-cfcedf47.mjs';
import '../../_chunks/dep-b4041200.mjs';
import '../../_common/js/log/log.mjs';
import '../../utils/withInstall.mjs';
import '../../button/button.mjs';
import '../../hooks/useRipple.mjs';
import '../../utils/set-style.mjs';
import '../../hooks/useKeepAnimation.mjs';
import '../../_chunks/dep-99920870.mjs';
import '../../_chunks/dep-a0b4a044.mjs';
import '../../_chunks/dep-79821ff2.mjs';
import '../../_chunks/dep-0bfbf721.mjs';
import '../../_chunks/dep-39cc276d.mjs';
import '../../_chunks/dep-6b22dd27.mjs';
import '../../_chunks/dep-c959a6fb.mjs';
import '../../_chunks/dep-0f0c89ff.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-c31e1d9e.mjs';
import '../../_chunks/dep-e3b14d70.mjs';
import '../../_chunks/dep-66d6733b.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-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 '../../hooks/useConfig.mjs';
import '../../config-provider/useConfig.mjs';
import '../../_chunks/dep-44417261.mjs';
import '../../_chunks/dep-bf74f1c2.mjs';
import '../../_chunks/dep-44f056cd.mjs';
import '../../_chunks/dep-23a0f453.mjs';
import '../../_chunks/dep-1cf2b129.mjs';
import '../../config-provider/type.mjs';
import '../../form/hooks.mjs';
import '../../button/props.mjs';
import '../../loading/directive.mjs';
import '../../loading/plugin.mjs';
import '../../utils/dom.mjs';
import '../../utils/easing.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 '../../button/style/css.mjs';
import '../../button/type.mjs';
import '../../image-viewer/image-viewer.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 '../../popup/container.mjs';
import '../../hooks/useResizeObserver.mjs';
import '../../hooks/icon.mjs';
import '../../hooks/slot.mjs';
import '../../hooks/useDestroyOnClose.mjs';
import '../../hooks/useVirtualScroll.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 '../../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';

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 DraggerFile = defineComponent({
  name: "UploadDraggerFile",
  props: _objectSpread(_objectSpread({}, commonProps), {}, {
    trigger: Function,
    triggerUpload: Function,
    uploadFiles: Function,
    cancelUpload: Function,
    dragEvents: Object
  }),
  setup: function setup(props, _ref) {
    var slots = _ref.slots;
    var _toRefs = toRefs(props),
      displayFiles = _toRefs.displayFiles,
      disabled = _toRefs.disabled;
    var locale = computed(function () {
      return props.locale;
    });
    var renderTNodeJSX = useTNodeJSX();
    var _useCommonClassName = useCommonClassName(),
      sizeClassNames = _useCommonClassName.sizeClassNames;
    var uploadPrefix = "".concat(props.classPrefix, "-upload");
    var drag = useDrag(props.dragEvents);
    var dragActive = drag.dragActive;
    var draggerFileRef = ref();
    var classes = computed(function () {
      var _displayFiles$value$;
      return ["".concat(uploadPrefix, "__dragger"), _defineProperty({}, "".concat(uploadPrefix, "__dragger-center"), !displayFiles.value[0]), _defineProperty({}, "".concat(uploadPrefix, "__dragger-error"), ((_displayFiles$value$ = displayFiles.value[0]) === null || _displayFiles$value$ === void 0 ? void 0 : _displayFiles$value$.status) === "fail")];
    });
    var _useGlobalIcon = useGlobalIcon({
        CheckCircleFilledIcon: CheckCircleFilledIcon,
        ErrorCircleFilledIcon: ErrorCircleFilledIcon
      }),
      CheckCircleFilledIcon$1 = _useGlobalIcon.CheckCircleFilledIcon,
      ErrorCircleFilledIcon$1 = _useGlobalIcon.ErrorCircleFilledIcon;
    var renderImage = function renderImage() {
      var _file$response;
      if (!props.displayFiles.length) return;
      var file = displayFiles.value[0];
      if (!file) return null;
      var url = (file === null || file === void 0 ? void 0 : file.url) || (file === null || file === void 0 ? void 0 : (_file$response = file.response) === null || _file$response === void 0 ? void 0 : _file$response.url);
      return createVNode("div", {
        "class": "".concat(uploadPrefix, "__dragger-img-wrap")
      }, [url && createVNode(ImageViewer, {
        "images": [url],
        "trigger": function trigger(h2, _ref4) {
          var open = _ref4.open;
          return createVNode("img", {
            "src": url,
            "onClick": open
          }, null);
        }
      }, null)]);
    };
    var renderUploading = function renderUploading() {
      if (!props.displayFiles.length) return;
      var file = displayFiles.value[0];
      if (!file) return null;
      if ((file === null || file === void 0 ? void 0 : file.status) === "progress") {
        return createVNode("div", {
          "class": "".concat(uploadPrefix, "__single-progress")
        }, [createVNode(Loading, null, null), createVNode("span", {
          "class": "".concat(uploadPrefix, "__single-percent")
        }, [file.percent, "%"])]);
      }
    };
    var renderMainPreview = function renderMainPreview() {
      var _locale$value;
      var file = displayFiles.value[0];
      var fileName = props.abridgeName ? abridgeName.apply(void 0, [file.name].concat(_toConsumableArray(props.abridgeName))) : file.name;
      var fileInfo = [createVNode("div", {
        "class": "".concat(uploadPrefix, "__dragger-text"),
        "key": "info"
      }, [createVNode("span", {
        "class": "".concat(uploadPrefix, "__single-name")
      }, [fileName]), file.status === "progress" && renderUploading(), file.status === "success" && createVNode(CheckCircleFilledIcon$1, null, null), file.status === "fail" && createVNode(ErrorCircleFilledIcon$1, null, null)]), createVNode("small", {
        "class": "".concat(sizeClassNames.small),
        "key": "size"
      }, [locale.value.file.fileSizeText, "\uFF1A", getFileSizeText(file.size)]), createVNode("small", {
        "class": "".concat(sizeClassNames.small),
        "key": "time"
      }, [locale.value.file.fileOperationDateText, "\uFF1A", file.uploadTime || "-"])];
      return createVNode("div", {
        "class": "".concat(uploadPrefix, "__dragger-progress")
      }, [props.theme === "image" && renderImage(), createVNode("div", {
        "class": "".concat(uploadPrefix, "__dragger-progress-info")
      }, [renderTNodeJSX("fileListDisplay", {
        params: {
          files: props.displayFiles
        }
      }) || fileInfo, createVNode("div", {
        "class": "".concat(uploadPrefix, "__dragger-btns")
      }, [["progress", "waiting"].includes(file.status) && !disabled.value && createVNode(Button, {
        "theme": "primary",
        "variant": "text",
        "class": "".concat(uploadPrefix, "__dragger-progress-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,
            file: props.toUploadFiles[0] || props.files[0]
          });
        }
      }, {
        "default": function _default() {
          return [(_locale$value = locale.value) === null || _locale$value === void 0 ? void 0 : _locale$value.cancelUploadText];
        }
      }), !props.autoUpload && file.status === "waiting" && createVNode(Button, {
        "theme": "primary",
        "variant": "text",
        "disabled": disabled.value,
        "onClick": function onClick() {
          var _props$uploadFiles;
          return (_props$uploadFiles = props.uploadFiles) === null || _props$uploadFiles === void 0 ? void 0 : _props$uploadFiles.call(props);
        },
        "class": "".concat(uploadPrefix, "__dragger-upload-btn")
      }, {
        "default": function _default() {
          return [locale.value.triggerUploadText.normal];
        }
      })]), ["fail", "success"].includes(file === null || file === void 0 ? void 0 : file.status) && !disabled.value && createVNode("div", {
        "class": "".concat(uploadPrefix, "__dragger-btns")
      }, [createVNode(Button, {
        "theme": "primary",
        "variant": "text",
        "disabled": disabled.value,
        "class": "".concat(uploadPrefix, "__dragger-progress-cancel"),
        "onClick": props.triggerUpload
      }, {
        "default": function _default() {
          return [locale.value.triggerUploadText.reupload];
        }
      }), createVNode(Button, {
        "theme": "danger",
        "variant": "text",
        "disabled": disabled.value,
        "class": "".concat(uploadPrefix, "__dragger-delete-btn"),
        "onClick": function onClick(e) {
          return props.onRemove({
            e: e,
            index: 0,
            file: file
          });
        }
      }, {
        "default": function _default() {
          return [locale.value.triggerUploadText["delete"]];
        }
      })])])]);
    };
    var renderDefaultDragElement = function renderDefaultDragElement() {
      var _locale$value$trigger;
      var unActiveElement = createVNode("div", null, [createVNode("span", {
        "class": "".concat(uploadPrefix, "--highlight")
      }, [(_locale$value$trigger = locale.value.triggerUploadText) === null || _locale$value$trigger === void 0 ? void 0 : _locale$value$trigger.normal]), createVNode("span", null, ["\xA0\xA0/\xA0\xA0", locale.value.dragger.draggingText])]);
      var activeElement = createVNode("div", null, [locale.value.dragger.dragDropText]);
      return dragActive.value ? activeElement : unActiveElement;
    };
    var getContent = function getContent() {
      var _slots$default;
      var file = displayFiles.value[0];
      if (file && (["progress", "success", "fail", "waiting"].includes(file.status) || !file.status)) return renderMainPreview();
      return createVNode("div", {
        "class": "".concat(uploadPrefix, "__trigger"),
        "onClick": props.triggerUpload
      }, [((_slots$default = slots["default"]) === null || _slots$default === void 0 ? void 0 : _slots$default.call(slots)) || renderDefaultDragElement()]);
    };
    return function () {
      var _props$trigger;
      return createVNode("div", {
        "ref": draggerFileRef,
        "class": classes.value,
        "onDrop": drag.handleDrop,
        "onDragenter": drag.handleDragenter,
        "onDragover": drag.handleDragover,
        "onDragleave": drag.handleDragleave
      }, [((_props$trigger = props.trigger) === null || _props$trigger === void 0 ? void 0 : _props$trigger.call(props, h, {
        files: displayFiles.value,
        dragActive: dragActive.value
      })) || getContent()]);
    };
  }
});

export { DraggerFile as default };
//# sourceMappingURL=dragger-file.mjs.map
