/**
 * ldesign v0.2.14
 * (c) 2022/11/2 16:16 built by swimly
 * @license MIT
 */

'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var VueCompositionAPI = require('@vue/composition-api');
var iconsVue = require('@ldesign/icons-vue');
var utils = require('../../../chunks/utils2.js');
var components_button_index = require('../../button/index.js');
var components_upload_const = require('../const.js');
var hooks_useCommonClassname = require('../../../hooks/use-common-classname.js');
var components_loading_index = require('../../loading/index.js');
var components_upload_hooks_useDrag = require('../hooks/use-drag.js');
var hooks_useGlobalIcon = require('../../../hooks/use-global-icon.js');
var components_imageViewer_index = require('../../image-viewer/index.js');
require('../../../chunks/log.js');
require('../../../chunks/_commonjsHelpers-2e6815bd.js');
require('../../../utils/with-install.js');
require('vue');
require('lodash');
require('../../../config.js');
require('../../button/button.js');
require('../../../utils/render-node.js');
require('../../../utils/ripple.js');
require('../../../chunks/set-style.js');
require('../../config-provider/config-receiver.js');
require('lodash/mergeWith');
require('../../config-provider/context.js');
require('../../../chunks/zh_CN.js');
require('../../../utils/mixins.js');
require('../../button/props.js');
require('../../loading/loading.js');
require('../../../utils/dom.js');
require('raf');
require('lodash/isString');
require('../../../utils/easing.js');
require('../../../utils/transfer-dom.js');
require('../../loading/props.js');
require('../../loading/icon/gradient.js');
require('../../../chunks/defineProperty-838e4192.js');
require('../../../chunks/helper2.js');
require('../../loading/plugin.js');
require('../../config-provider/useConfig.js');
require('../../image-viewer/image-viewer.js');
require('lodash/kebabCase');
require('../../../hooks/use-default-value.js');
require('../../../hooks/use-config.js');
require('../../image-viewer/props.js');
require('../../image-viewer/base/ImageModalIcon.js');
require('../../../hooks/lnode.js');
require('lodash/isEmpty');
require('lodash/isFunction');
require('lodash/camelCase');
require('../../../hooks/render-lnode.js');
require('../../image-viewer/base/ImageViewerUtils.js');
require('../../tooltip/index.js');
require('../../../utils/map-props.js');
require('../../tooltip/tooltip.js');
require('../../../chunks/helper.js');
require('../../popup/props.js');
require('../../popup/popup.js');
require('@popperjs/core');
require('../../../utils/helper.js');
require('../../popup/container.js');
require('../../tooltip/props.js');
require('../../image-viewer/utils.js');
require('../../image-viewer/base/ImageItem.js');
require('../../image-viewer/hooks/index.js');
require('../../image-viewer/base/ImageViewerModal.js');
require('../../dialog/index.js');
require('../../dialog/dialog.js');
require('lodash/isNumber');
require('lodash/throttle');
require('../../../utils/event.js');
require('../../../hooks/use-destroy-onclose.js');
require('../../dialog/props.js');
require('../../dialog/mixins/action.js');
require('lodash/isObject');
require('../../dialog/stack.js');
require('../../dialog/plugin.js');
require('../../image-viewer/const.js');
require('../../image-viewer/base/Container.js');

var DraggerFile = VueCompositionAPI.defineComponent({
  name: "UploadDraggerFile",
  props: {
    ...components_upload_const.commonProps,
    trigger: Function,
    triggerUpload: Function,
    uploadFiles: Function,
    cancelUpload: Function,
    dragEvents: Object
  },
  setup(props) {
    const {
      displayFiles
    } = VueCompositionAPI.toRefs(props);
    const {
      sizeClassNames
    } = hooks_useCommonClassname["default"]();
    const uploadPrefix = `${props.classPrefix}-upload`;
    const drag = components_upload_hooks_useDrag["default"](props.dragEvents);
    const {
      dragActive
    } = drag;
    const draggerFileRef = VueCompositionAPI.ref();
    const classes = VueCompositionAPI.computed(() => {
      var _displayFiles$value$;
      return [`${uploadPrefix}__dragger`, {
        [`${uploadPrefix}__dragger-center`]: !displayFiles.value[0]
      }, {
        [`${uploadPrefix}__dragger-error`]: ((_displayFiles$value$ = displayFiles.value[0]) === null || _displayFiles$value$ === void 0 ? void 0 : _displayFiles$value$.status) === "fail"
      }];
    });
    const icons = hooks_useGlobalIcon.useGlobalIcon({
      CheckCircleFilledIcon: iconsVue.CheckCircleFilledIcon,
      ErrorCircleFilledIcon: iconsVue.ErrorCircleFilledIcon
    });
    return {
      drag,
      dragActive,
      draggerFileRef,
      classes,
      sizeClassNames,
      uploadPrefix,
      icons
    };
  },
  methods: {
    renderImage() {
      var _file$response;
      const h = this.$createElement;
      const file = this.displayFiles[0];
      if (!file) return null;
      const url = file.url || ((_file$response = file.response) === null || _file$response === void 0 ? void 0 : _file$response.url);
      return h("div", {
        "class": `${this.uploadPrefix}__dragger-img-wrap`
      }, [url && h(components_imageViewer_index.ImageViewer, {
        "attrs": {
          "images": [url],
          "trigger": (h2, _ref) => {
            let {
              open
            } = _ref;
            return h("img", {
              "attrs": {
                "src": url
              },
              "on": {
                "click": open
              },
              "style": {
                maxWidth: "100%",
                maxHeight: "100%"
              }
            });
          }
        },
        "style": {
          maxWidth: "120px",
          maxHeight: "120px"
        }
      })]);
    },
    renderUploading() {
      const h = this.$createElement;
      const file = this.displayFiles[0];
      if (!file) return null;
      if (file.status === "progress") {
        return h("div", {
          "class": `${this.uploadPrefix}__single-progress`
        }, [h(components_loading_index.Loading), h("span", {
          "class": `${this.uploadPrefix}__single-percent`
        }, [file.percent, "%"])]);
      }
    },
    renderMainPreview() {
      var _this$locale;
      const h = this.$createElement;
      const file = this.displayFiles[0];
      if (!file) return null;
      const {
        CheckCircleFilledIcon,
        ErrorCircleFilledIcon
      } = this.icons;
      const fileName = this.abridgeName ? utils.abridgeName(file.name, ...this.abridgeName) : file.name;
      return h("div", {
        "class": `${this.uploadPrefix}__dragger-progress`
      }, [this.theme === "image" && this.renderImage(), h("div", {
        "class": `${this.uploadPrefix}__dragger-progress-info`
      }, [h("div", {
        "class": `${this.uploadPrefix}__dragger-text`
      }, [h("span", {
        "class": `${this.uploadPrefix}__single-name`
      }, [fileName]), file.status === "progress" && this.renderUploading(), file.status === "success" && h(CheckCircleFilledIcon), file.status === "fail" && h(ErrorCircleFilledIcon)]), h("small", {
        "class": `${this.sizeClassNames.small}`
      }, [this.locale.file.fileSizeText, "\uFF1A", utils.getFileSizeText(file.size)]), h("small", {
        "class": `${this.sizeClassNames.small}`
      }, [this.locale.file.fileOperationDateText, "\uFF1A", file.uploadTime || "-"]), h("div", {
        "class": `${this.uploadPrefix}__dragger-btns`
      }, [["progress", "waiting"].includes(file.status) && !this.disabled && h(components_button_index.Button, {
        "attrs": {
          "theme": "primary",
          "variant": "text"
        },
        "class": `${this.uploadPrefix}__dragger-progress-cancel`,
        "on": {
          "click": e => {
            var _this$cancelUpload;
            return (_this$cancelUpload = this.cancelUpload) === null || _this$cancelUpload === void 0 ? void 0 : _this$cancelUpload.call(this, {
              e,
              file: this.toUploadFiles[0] || this.files[0]
            });
          }
        }
      }, [(_this$locale = this.locale) === null || _this$locale === void 0 ? void 0 : _this$locale.cancelUploadText]), !this.autoUpload && file.status === "waiting" && h(components_button_index.Button, {
        "attrs": {
          "variant": "text",
          "theme": "primary",
          "disabled": this.disabled
        },
        "on": {
          "click": () => {
            var _this$uploadFiles;
            return (_this$uploadFiles = this.uploadFiles) === null || _this$uploadFiles === void 0 ? void 0 : _this$uploadFiles.call(this);
          }
        },
        "class": `${this.uploadPrefix}__dragger-upload-btn`
      }, [this.locale.triggerUploadText.normal])]), ["fail", "success"].includes(file === null || file === void 0 ? void 0 : file.status) && !this.disabled && h("div", {
        "class": `${this.uploadPrefix}__dragger-btns`
      }, [h(components_button_index.Button, {
        "attrs": {
          "theme": "primary",
          "variant": "text",
          "disabled": this.disabled
        },
        "class": `${this.uploadPrefix}__dragger-progress-cancel`,
        "on": {
          "click": this.triggerUpload
        }
      }, [this.locale.triggerUploadText.reupload]), h(components_button_index.Button, {
        "attrs": {
          "theme": "danger",
          "variant": "text",
          "disabled": this.disabled
        },
        "class": `${this.uploadPrefix}__dragger-delete-btn`,
        "on": {
          "click": e => this.onRemove({
            e,
            index: 0,
            file
          })
        }
      }, [this.locale.triggerUploadText.delete])])])]);
    },
    renderDefaultDragElement() {
      var _this$locale$triggerU;
      const h = this.$createElement;
      const unActiveElement = h("div", [h("span", {
        "class": `${this.uploadPrefix}--highlight`
      }, [(_this$locale$triggerU = this.locale.triggerUploadText) === null || _this$locale$triggerU === void 0 ? void 0 : _this$locale$triggerU.normal]), h("span", ["\xA0\xA0/\xA0\xA0", this.locale.dragger.draggingText])]);
      const activeElement = h("div", [this.locale.dragger.dragDropText]);
      return this.dragActive ? activeElement : unActiveElement;
    },
    getContent() {
      var _this$$scopedSlots$de, _this$$scopedSlots;
      const h = this.$createElement;
      const file = this.displayFiles[0];
      if (file && ["progress", "success", "fail", "waiting"].includes(file.status)) return this.renderMainPreview();
      return h("div", {
        "class": `${this.uploadPrefix}__trigger`,
        "on": {
          "click": this.triggerUpload
        }
      }, [((_this$$scopedSlots$de = (_this$$scopedSlots = this.$scopedSlots).default) === null || _this$$scopedSlots$de === void 0 ? void 0 : _this$$scopedSlots$de.call(_this$$scopedSlots, null)) || this.renderDefaultDragElement()]);
    }
  },
  render() {
    var _this$trigger;
    const h = arguments[0];
    return h("div", {
      "ref": "draggerFileRef",
      "class": this.classes,
      "on": {
        "drop": this.drag.handleDrop,
        "dragenter": this.drag.handleDragenter,
        "dragover": this.drag.handleDragover,
        "dragleave": this.drag.handleDragleave
      }
    }, [((_this$trigger = this.trigger) === null || _this$trigger === void 0 ? void 0 : _this$trigger.call(this, h, {
      files: this.displayFiles,
      dragActive: this.dragActive
    })) || this.getContent()]);
  }
});

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