/**
 * 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 _common_js_upload_utils = require('../../_common/js/upload/utils.js');
var button_index = require('../../button/index.js');
var upload_constants = require('../constants.js');
var hooks_useCommonClassName = require('../../hooks/useCommonClassName.js');
var loading_index = require('../../loading/index.js');
var upload_hooks_useDrag = require('../hooks/useDrag.js');
var hooks_useGlobalIcon = require('../../hooks/useGlobalIcon.js');
var imageViewer_index = require('../../image-viewer/index.js');
var hooks_tnode = require('../../hooks/tnode.js');
require('../../_common/js/log/log.js');
require('../../utils/withInstall.js');
require('../../button/button.js');
require('../../hooks/useRipple.js');
require('../../utils/set-style.js');
require('../../hooks/useKeepAnimation.js');
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-7f0559c3.js');
require('dayjs');
require('../../config-provider/useConfig.js');
require('lodash/cloneDeep');
require('lodash/isFunction');
require('lodash/isString');
require('../../hooks/useConfig.js');
require('../../form/hooks.js');
require('../../button/props.js');
require('../../loading/directive.js');
require('../../loading/plugin.js');
require('../../utils/dom.js');
require('../../utils/easing.js');
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/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('../../dialog/props.js');
require('../../dialog/plugin.js');
require('../../image-viewer/const.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 DraggerFile = vue.defineComponent({
  name: "UploadDraggerFile",
  props: _objectSpread(_objectSpread({}, upload_constants.commonProps), {}, {
    trigger: Function,
    triggerUpload: Function,
    uploadFiles: Function,
    cancelUpload: Function,
    dragEvents: Object
  }),
  setup: function setup(props, _ref) {
    var slots = _ref.slots;
    var _toRefs = vue.toRefs(props),
      displayFiles = _toRefs.displayFiles,
      disabled = _toRefs.disabled;
    var locale = vue.computed(function () {
      return props.locale;
    });
    var renderTNodeJSX = hooks_tnode.useTNodeJSX();
    var _useCommonClassName = hooks_useCommonClassName["default"](),
      sizeClassNames = _useCommonClassName.sizeClassNames;
    var uploadPrefix = "".concat(props.classPrefix, "-upload");
    var drag = upload_hooks_useDrag["default"](props.dragEvents);
    var dragActive = drag.dragActive;
    var draggerFileRef = vue.ref();
    var classes = vue.computed(function () {
      var _displayFiles$value$;
      return ["".concat(uploadPrefix, "__dragger"), _defineProperty__default["default"]({}, "".concat(uploadPrefix, "__dragger-center"), !displayFiles.value[0]), _defineProperty__default["default"]({}, "".concat(uploadPrefix, "__dragger-error"), ((_displayFiles$value$ = displayFiles.value[0]) === null || _displayFiles$value$ === void 0 ? void 0 : _displayFiles$value$.status) === "fail")];
    });
    var _useGlobalIcon = hooks_useGlobalIcon.useGlobalIcon({
        CheckCircleFilledIcon: iconsVueNext.CheckCircleFilledIcon,
        ErrorCircleFilledIcon: iconsVueNext.ErrorCircleFilledIcon
      }),
      CheckCircleFilledIcon = _useGlobalIcon.CheckCircleFilledIcon,
      ErrorCircleFilledIcon = _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 vue.createVNode("div", {
        "class": "".concat(uploadPrefix, "__dragger-img-wrap")
      }, [url && vue.createVNode(imageViewer_index.ImageViewer, {
        "images": [url],
        "trigger": function trigger(h2, _ref4) {
          var open = _ref4.open;
          return vue.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 vue.createVNode("div", {
          "class": "".concat(uploadPrefix, "__single-progress")
        }, [vue.createVNode(loading_index.Loading, null, null), vue.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 ? _common_js_upload_utils.abridgeName.apply(void 0, [file.name].concat(_toConsumableArray__default["default"](props.abridgeName))) : file.name;
      var fileInfo = [vue.createVNode("div", {
        "class": "".concat(uploadPrefix, "__dragger-text"),
        "key": "info"
      }, [vue.createVNode("span", {
        "class": "".concat(uploadPrefix, "__single-name")
      }, [fileName]), file.status === "progress" && renderUploading(), file.status === "success" && vue.createVNode(CheckCircleFilledIcon, null, null), file.status === "fail" && vue.createVNode(ErrorCircleFilledIcon, null, null)]), vue.createVNode("small", {
        "class": "".concat(sizeClassNames.small),
        "key": "size"
      }, [locale.value.file.fileSizeText, "\uFF1A", _common_js_upload_utils.getFileSizeText(file.size)]), vue.createVNode("small", {
        "class": "".concat(sizeClassNames.small),
        "key": "time"
      }, [locale.value.file.fileOperationDateText, "\uFF1A", file.uploadTime || "-"])];
      return vue.createVNode("div", {
        "class": "".concat(uploadPrefix, "__dragger-progress")
      }, [props.theme === "image" && renderImage(), vue.createVNode("div", {
        "class": "".concat(uploadPrefix, "__dragger-progress-info")
      }, [renderTNodeJSX("fileListDisplay", {
        params: {
          files: props.displayFiles
        }
      }) || fileInfo, vue.createVNode("div", {
        "class": "".concat(uploadPrefix, "__dragger-btns")
      }, [["progress", "waiting"].includes(file.status) && !disabled.value && vue.createVNode(button_index.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" && vue.createVNode(button_index.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 && vue.createVNode("div", {
        "class": "".concat(uploadPrefix, "__dragger-btns")
      }, [vue.createVNode(button_index.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];
        }
      }), vue.createVNode(button_index.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 = vue.createVNode("div", null, [vue.createVNode("span", {
        "class": "".concat(uploadPrefix, "--highlight")
      }, [(_locale$value$trigger = locale.value.triggerUploadText) === null || _locale$value$trigger === void 0 ? void 0 : _locale$value$trigger.normal]), vue.createVNode("span", null, ["\xA0\xA0/\xA0\xA0", locale.value.dragger.draggingText])]);
      var activeElement = vue.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 vue.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 vue.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, vue.h, {
        files: displayFiles.value,
        dragActive: dragActive.value
      })) || getContent()]);
    };
  }
});

exports["default"] = DraggerFile;
//# sourceMappingURL=dragger-file.js.map
