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

import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
import _defineProperty from '@babel/runtime/helpers/defineProperty';
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.js';
import { Button } from '../../button/index.js';
import { commonProps } from '../constants.js';
import useCommonClassName from '../../hooks/useCommonClassName.js';
import { Loading } from '../../loading/index.js';
import useDrag from '../hooks/useDrag.js';
import { useGlobalIcon } from '../../hooks/useGlobalIcon.js';
import { ImageViewer } from '../../image-viewer/index.js';
import '../../hooks/index.js';
import { useTNodeJSX } from '../../hooks/tnode.js';
import '../../_common/js/log/log.js';
import '../../utils/withInstall.js';
import '../../button/button.js';
import '../../hooks/useRipple.js';
import '../../utils/set-style.js';
import '../../hooks/useKeepAnimation.js';
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 '../../hooks/useConfig.js';
import '../../config-provider/useConfig.js';
import 'lodash/cloneDeep';
import 'lodash/isFunction';
import 'lodash/isString';
import '../../config-provider/type.js';
import '../../form/hooks.js';
import '../../button/props.js';
import '../../loading/directive.js';
import '../../loading/plugin.js';
import '../../utils/dom.js';
import '../../utils/easing.js';
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 '../../loading/style';
import '../../loading/type.js';
import '../../button/style';
import '../../button/type.js';
import '../../image-viewer/image-viewer.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 '../../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 '../../dialog/stack.js';
import '../../dialog/hooks.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 '../../hooks/icon.js';
import '../../hooks/slot.js';
import '../../hooks/useVirtualScroll.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 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.js.map
