/**
 * ldesign v0.2.22
 * (c) 2022/12/7 16:21 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/useCommonClassName.js');
var components_loading_index = require('../../loading/index.js');
var components_upload_hooks_useDrag = require('../hooks/use-drag.js');
var hooks_useGlobalIcon = require('../../../hooks/useGlobalIcon.js');
var components_imageViewer_index = require('../../image-viewer/index.js');
require('../../../chunks/log.js');
require('../../../chunks/_commonjsHelpers-fe796db6.js');
require('../../../utils/withInstall.js');
require('vue');
require('lodash/capitalize');
require('../../../config.js');
require('../../button/button.js');
require('../../../utils/render-node.js');
require('lodash');
require('../../../utils/ripple.js');
require('../../../chunks/set-style.js');
require('../../config-provider/config-receiver.js');
require('lodash/mergeWith');
require('../../config-provider/context.js');
require('lodash/merge');
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-19da3d4c.js');
require('../../../chunks/helper2.js');
require('../../loading/plugin.js');
require('../../config-provider/useConfig.js');
require('../../image-viewer/image-viewer.js');
require('../../../hooks/useVModel.js');
require('lodash/kebabCase');
require('../../../hooks/useDefaultValue.js');
require('../../../hooks/useConfig.js');
require('../../../utils/helper.js');
require('lodash/camelCase');
require('../../image-viewer/props.js');
require('../../image-viewer/base/ImageModalIcon.js');
require('../../../hooks/lnode.js');
require('lodash/isEmpty');
require('lodash/isFunction');
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('../../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/useDestroyOnClose.js');
require('../../dialog/props.js');
require('../../dialog/actions.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(() => [`${uploadPrefix}__dragger`, {
      [`${uploadPrefix}__dragger-center`]: !displayFiles.value[0]
    }, {
      [`${uploadPrefix}__dragger-error`]: displayFiles.value[0]?.status === "fail"
    }]);
    const icons = hooks_useGlobalIcon.useGlobalIcon({
      CheckCircleFilledIcon: iconsVue.CheckCircleFilledIcon,
      ErrorCircleFilledIcon: iconsVue.ErrorCircleFilledIcon
    });
    return {
      drag,
      dragActive,
      draggerFileRef,
      classes,
      sizeClassNames,
      uploadPrefix,
      icons
    };
  },
  methods: {
    renderImage() {
      const h = this.$createElement;
      const file = this.displayFiles[0];
      if (!file) return null;
      const url = file.url || 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() {
      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 => this.cancelUpload?.({
            e,
            file: this.toUploadFiles[0] || this.files[0]
          })
        }
      }, [this.locale?.cancelUploadText]), !this.autoUpload && file.status === "waiting" && h(components_button_index.Button, {
        "attrs": {
          "variant": "text",
          "theme": "primary",
          "disabled": this.disabled
        },
        "on": {
          "click": () => this.uploadFiles?.()
        },
        "class": `${this.uploadPrefix}__dragger-upload-btn`
      }, [this.locale.triggerUploadText.normal])]), ["fail", "success"].includes(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() {
      const h = this.$createElement;
      const unActiveElement = h("div", [h("span", {
        "class": `${this.uploadPrefix}--highlight`
      }, [this.locale.triggerUploadText?.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() {
      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.default?.(null) || this.renderDefaultDragElement()]);
    }
  },
  render() {
    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?.(h, {
      files: this.displayFiles,
      dragActive: this.dragActive
    }) || this.getContent()]);
  }
});

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