/**
 * ldesign v0.2.2
 * (c) 2022年9月20日 swimly
 * @license MIT
 */

import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { ErrorCircleFilledIcon, CheckCircleFilledIcon } from '@ldesign/icons-vue';
import { a as abridgeName, r as returnFileSize, g as getCurrentDate } from '../../chunks/utils.js';
import { Loading } from '../loading/index.js';
import { Button } from '../button/index.js';
import props from './props.js';
import mixins from '../../utils/mixins.js';
import getConfigReceiverMixins, { getGlobalIconMixins } from '../config-provider/config-receiver.js';
import '../../chunks/defineProperty-28395935.js';
import '../../chunks/log.js';
import '../loading/loading.js';
import '../loading/icon/gradient.js';
import 'vue';
import '../../chunks/set-style.js';
import '../../chunks/helper2.js';
import '@babel/runtime/helpers/toConsumableArray';
import '@babel/runtime/helpers/slicedToArray';
import '../../config.js';
import '../../utils/dom.js';
import 'raf';
import 'lodash/isString';
import '../../utils/easing.js';
import '../../utils/render-node.js';
import '@babel/runtime/helpers/typeof';
import 'lodash/camelCase';
import 'lodash/kebabCase';
import '../../utils/transfer-dom.js';
import '../loading/props.js';
import 'lodash/mergeWith';
import 'lodash';
import '../config-provider/context.js';
import '../../chunks/zh_CN.js';
import '../config-provider/type.js';
import '../../utils/with-install.js';
import '../loading/style/css.js';
import '../loading/type.js';
import '../loading/plugin.js';
import '../button/button.js';
import '../button/props.js';
import '../../utils/ripple.js';
import '../button/style/css.js';
import '../button/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; }
var LDragger = mixins(getConfigReceiverMixins("upload"), getGlobalIconMixins()).extend({
  name: "LUploadDragger",
  components: {
    LLoading: Loading,
    LButton: Button
  },
  props: {
    showUploadProgress: props.showUploadProgress,
    file: {
      type: Object
    },
    loadingFile: {
      type: Object
    },
    display: {
      type: String,
      validator: function validator(val) {
        return ["file", "file-input", "image", "custom"].includes(val);
      }
    },
    cancel: Function,
    trigger: Function,
    remove: Function,
    upload: Function,
    autoUpload: Boolean,
    locale: props.locale
  },
  data: function data() {
    return {
      target: null,
      dragActive: false
    };
  },
  computed: {
    isImage: function isImage() {
      return this.display === "image";
    },
    imageUrl: function imageUrl() {
      return this.loadingFile && this.loadingFile.url || this.file && this.file.url;
    },
    percent: function percent() {
      return this.loadingFile && this.loadingFile.percent;
    },
    inputName: function inputName() {
      return this.loadingFile && this.loadingFile.name || this.file && this.file.name;
    },
    classes: function classes() {
      return ["".concat(this.componentName, "__dragger"), _defineProperty({}, "".concat(this.componentName, "__dragger-center"), !this.loadingFile && !this.file), _defineProperty({}, "".concat(this.componentName, "__dragger-error"), this.loadingFile && this.loadingFile.status === "fail")];
    },
    size: function size() {
      return this.loadingFile && this.loadingFile.size || this.file && this.file.size;
    },
    showResultOperate: function showResultOperate() {
      var _this$file, _this$loadingFile;

      return Boolean(!this.loadingFile && ((_this$file = this.file) === null || _this$file === void 0 ? void 0 : _this$file.name)) || ["success", "fail"].includes((_this$loadingFile = this.loadingFile) === null || _this$loadingFile === void 0 ? void 0 : _this$loadingFile.status);
    }
  },
  methods: {
    handleDrop: function handleDrop(event) {
      event.preventDefault();
      this.$emit("change", event.dataTransfer.files);
      this.$emit("dragleave", event);
      this.dragActive = false;
    },
    handleDragenter: function handleDragenter(event) {
      this.target = event.target;
      event.preventDefault();
      this.$emit("dragenter", event);
      this.dragActive = true;
    },
    handleDragleave: function handleDragleave(event) {
      if (this.target !== event.target) return;
      event.preventDefault();
      this.$emit("dragleave", event);
      this.dragActive = false;
    },
    handleDragover: function handleDragover(event) {
      event.preventDefault();
    },
    renderDefaultDragElement: function renderDefaultDragElement() {
      var _this$locale, _this$locale$triggerU, _this$locale2, _this$locale2$dragger, _this$locale3, _this$locale3$dragger;

      var h = this.$createElement;
      var unActiveElement = h("div", [h("span", {
        "class": "".concat(this.componentName, "--highlight")
      }, [((_this$locale = this.locale) === null || _this$locale === void 0 ? void 0 : (_this$locale$triggerU = _this$locale.triggerUploadText) === null || _this$locale$triggerU === void 0 ? void 0 : _this$locale$triggerU.normal) || this.global.triggerUploadText.normal]), h("span", ["\xA0\xA0/\xA0\xA0", ((_this$locale2 = this.locale) === null || _this$locale2 === void 0 ? void 0 : (_this$locale2$dragger = _this$locale2.dragger) === null || _this$locale2$dragger === void 0 ? void 0 : _this$locale2$dragger.draggingText) || this.global.dragger.draggingText])]);
      var activeElement = h("div", [((_this$locale3 = this.locale) === null || _this$locale3 === void 0 ? void 0 : (_this$locale3$dragger = _this$locale3.dragger) === null || _this$locale3$dragger === void 0 ? void 0 : _this$locale3$dragger.dragDropText) || this.global.dragger.dragDropText]);
      return this.dragActive ? activeElement : unActiveElement;
    },
    renderImage: function renderImage() {
      var h = this.$createElement;
      return h("div", {
        "class": "".concat(this.componentName, "__dragger-img-wrap")
      }, [this.imageUrl && h("img", {
        "attrs": {
          "src": this.imageUrl || "default.png"
        }
      })]);
    },
    renderUploading: function renderUploading() {
      var h = this.$createElement;

      if (this.loadingFile.status === "fail") {
        var _this$useGlobalIcon = this.useGlobalIcon({
          ErrorCircleFilledIcon: ErrorCircleFilledIcon
        }),
            ErrorCircleFilledIcon$1 = _this$useGlobalIcon.ErrorCircleFilledIcon;

        return h(ErrorCircleFilledIcon$1);
      }

      if (this.loadingFile.status === "progress" && this.showUploadProgress) {
        return h("div", {
          "class": "".concat(this.componentName, "__single-progress")
        }, [h("l-loading"), h("span", {
          "class": "".concat(this.componentName, "__single-percent")
        }, [Math.min(this.loadingFile.percent, 99), "%"])]);
      }
    },
    reUpload: function reUpload(e) {
      e.stopPropagation();
      this.remove({
        e: e,
        file: this.file
      });
      this.trigger(e);
    },
    renderProgress: function renderProgress() {
      var _this$locale4,
          _this$locale4$file,
          _this$locale5,
          _this$locale5$file,
          _this$loadingFile2,
          _this = this,
          _this$locale6,
          _this$loadingFile3,
          _this$locale7,
          _this$locale7$trigger,
          _this$locale8,
          _this$locale8$trigger,
          _this$locale9,
          _this$locale9$trigger;

      var h = this.$createElement;

      var _this$useGlobalIcon2 = this.useGlobalIcon({
        CheckCircleFilledIcon: CheckCircleFilledIcon
      }),
          CheckCircleFilledIcon$1 = _this$useGlobalIcon2.CheckCircleFilledIcon;

      return h("div", {
        "class": "".concat(this.componentName, "__dragger-progress")
      }, [this.isImage && this.renderImage(), h("div", {
        "class": "".concat(this.componentName, "__dragger-progress-info")
      }, [h("div", {
        "class": "".concat(this.componentName, "__dragger-text")
      }, [h("span", {
        "class": "".concat(this.componentName, "__single-name")
      }, [abridgeName(this.inputName)]), this.loadingFile && this.renderUploading(), !this.loadingFile && !!this.file && h(CheckCircleFilledIcon$1)]), h("small", {
        "class": "".concat(this.classPrefix, "-size-s")
      }, [((_this$locale4 = this.locale) === null || _this$locale4 === void 0 ? void 0 : (_this$locale4$file = _this$locale4.file) === null || _this$locale4$file === void 0 ? void 0 : _this$locale4$file.fileSizeText) || this.global.file.fileSizeText, "\uFF1A", returnFileSize(this.size)]), h("small", {
        "class": "".concat(this.classPrefix, "-size-s")
      }, [((_this$locale5 = this.locale) === null || _this$locale5 === void 0 ? void 0 : (_this$locale5$file = _this$locale5.file) === null || _this$locale5$file === void 0 ? void 0 : _this$locale5$file.fileOperationDateText) || this.global.file.fileOperationDateText, "\uFF1A", getCurrentDate()]), h("div", {
        "class": "".concat(this.componentName, "__dragger-btns")
      }, [["progress", "waiting"].includes((_this$loadingFile2 = this.loadingFile) === null || _this$loadingFile2 === void 0 ? void 0 : _this$loadingFile2.status) && h("l-button", {
        "attrs": {
          "theme": "primary",
          "variant": "text"
        },
        "class": "".concat(this.componentName, "__dragger-progress-cancel"),
        "on": {
          "click": function click(e) {
            var _this$cancel;

            (_this$cancel = _this.cancel) === null || _this$cancel === void 0 ? void 0 : _this$cancel.call(_this, e);
            e.stopPropagation();
          }
        }
      }, [((_this$locale6 = this.locale) === null || _this$locale6 === void 0 ? void 0 : _this$locale6.cancelUploadText) || this.global.cancelUploadText]), !this.autoUpload && ((_this$loadingFile3 = this.loadingFile) === null || _this$loadingFile3 === void 0 ? void 0 : _this$loadingFile3.status) === "waiting" && h("l-button", {
        "attrs": {
          "theme": "primary",
          "variant": "text"
        },
        "on": {
          "click": function click(e) {
            _this.upload(_objectSpread({}, _this.loadingFile), e);

            e.stopPropagation();
          }
        }
      }, [((_this$locale7 = this.locale) === null || _this$locale7 === void 0 ? void 0 : (_this$locale7$trigger = _this$locale7.triggerUploadText) === null || _this$locale7$trigger === void 0 ? void 0 : _this$locale7$trigger.normal) || this.global.triggerUploadText.normal])]), this.showResultOperate && h("div", {
        "class": "".concat(this.componentName, "__dragger-btns")
      }, [h("l-button", {
        "attrs": {
          "theme": "primary",
          "variant": "text"
        },
        "class": "".concat(this.componentName, "__dragger-progress-cancel"),
        "on": {
          "click": this.reUpload
        }
      }, [((_this$locale8 = this.locale) === null || _this$locale8 === void 0 ? void 0 : (_this$locale8$trigger = _this$locale8.triggerUploadText) === null || _this$locale8$trigger === void 0 ? void 0 : _this$locale8$trigger.reupload) || this.global.triggerUploadText.reupload]), h("l-button", {
        "attrs": {
          "theme": "primary",
          "variant": "text"
        },
        "on": {
          "click": function click(e) {
            var _this$remove;

            (_this$remove = _this.remove) === null || _this$remove === void 0 ? void 0 : _this$remove.call(_this, {
              e: e,
              file: _this.file
            });
            e.stopPropagation();
          }
        }
      }, [((_this$locale9 = this.locale) === null || _this$locale9 === void 0 ? void 0 : (_this$locale9$trigger = _this$locale9.triggerUploadText) === null || _this$locale9$trigger === void 0 ? void 0 : _this$locale9$trigger["delete"]) || this.global.triggerUploadText["delete"]])])])]);
    }
  },
  render: function render() {
    var h = arguments[0];
    var content = null;

    if ((this.loadingFile || this.file) && this.display !== "custom") {
      content = this.renderProgress();
    } else {
      content = h("div", {
        "class": "".concat(this.componentName, "__trigger"),
        "on": {
          "click": this.trigger
        }
      }, [this.$scopedSlots["default"] && this.$scopedSlots["default"](null) || this.renderDefaultDragElement()]);
    }

    return h("div", {
      "class": this.classes,
      "on": {
        "drop": this.handleDrop,
        "dragenter": this.handleDragenter,
        "dragover": this.handleDragover,
        "dragleave": this.handleDragleave
      }
    }, [content]);
  }
});

export { LDragger as default };
//# sourceMappingURL=dragger.js.map
