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

'use strict';

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

var helper = require('../../chunks/helper.js');
var VueCompositionAPI = require('@vue/composition-api');
var iconsVue = require('@ldesign/icons-vue');
var components_button_index = require('../button/index.js');
var utils_renderNode = require('../../utils/render-node.js');
var components_upload_props = require('./props.js');
var components_upload_themes_normalFile = require('./themes/normal-file.js');
var components_upload_themes_draggerFile = require('./themes/dragger-file.js');
var components_upload_themes_imageCard = require('./themes/image-card.js');
var components_upload_themes_multipleFlowList = require('./themes/multiple-flow-list.js');
var components_upload_hooks_useUpload = require('./hooks/use-upload.js');
var components_upload_themes_customFile = require('./themes/custom-file.js');
require('../../utils/with-install.js');
require('vue');
require('lodash');
require('../../config.js');
require('../button/button.js');
require('../loading/index.js');
require('../loading/loading.js');
require('../../utils/dom.js');
require('raf');
require('lodash/isString');
require('../../chunks/log.js');
require('../../chunks/_commonjsHelpers-2e6815bd.js');
require('../../utils/easing.js');
require('../../utils/transfer-dom.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('../loading/props.js');
require('../loading/icon/gradient.js');
require('../../chunks/defineProperty-838e4192.js');
require('../../chunks/set-style.js');
require('../../chunks/helper2.js');
require('../loading/plugin.js');
require('../../utils/ripple.js');
require('../button/props.js');
require('../../chunks/utils2.js');
require('../link/index.js');
require('../link/link.js');
require('../link/props.js');
require('../../hooks/use-global-icon.js');
require('../config-provider/useConfig.js');
require('./const.js');
require('../../hooks/use-common-classname.js');
require('./hooks/use-drag.js');
require('../image-viewer/index.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('../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');
require('lodash/merge');
require('../../hooks/use-vmodel.js');

var _Upload = VueCompositionAPI.defineComponent({
  name: "LUpload",
  props: components_upload_props["default"],
  setup(props2, context) {
    const uploadData = components_upload_hooks_useUpload["default"](props2, context);
    const {
      localeConfig,
      classPrefix,
      toUploadFiles,
      displayFiles,
      uploadValue,
      sizeOverLimitMessage,
      uploading,
      tipsClasses,
      errorClasses,
      innerDisabled,
      onInnerRemove,
      onDragFileChange
    } = uploadData;
    const commonDisplayFileProps = VueCompositionAPI.computed(() => ({
      files: uploadValue.value,
      toUploadFiles: toUploadFiles.value,
      displayFiles: displayFiles.value,
      theme: props2.theme,
      placeholder: props2.placeholder,
      disabled: innerDisabled.value,
      tips: props2.tips,
      status: props2.status,
      sizeOverLimitMessage: sizeOverLimitMessage.value,
      uploading: uploading.value,
      classPrefix: classPrefix.value,
      tipsClasses,
      errorClasses,
      locale: localeConfig.value,
      autoUpload: props2.autoUpload,
      abridgeName: props2.abridgeName,
      fileListDisplay: props2.fileListDisplay,
      onRemove: onInnerRemove
    }));
    const dragProps = VueCompositionAPI.computed(() => ({
      onDragFileChange,
      onDragenter: p => {
        var _props2$onDragenter;
        (_props2$onDragenter = props2.onDragenter) === null || _props2$onDragenter === void 0 ? void 0 : _props2$onDragenter.call(props2, p);
        context.emit("dragenter", p);
      },
      onDragleave: p => {
        var _props2$onDragleave;
        (_props2$onDragleave = props2.onDragleave) === null || _props2$onDragleave === void 0 ? void 0 : _props2$onDragleave.call(props2, p);
        context.emit("dragleave", p);
      },
      onDrop: p => {
        var _props2$onDrop;
        (_props2$onDrop = props2.onDrop) === null || _props2$onDrop === void 0 ? void 0 : _props2$onDrop.call(props2, p);
        context.emit("drop", p);
      }
    }));
    return {
      ...uploadData,
      commonDisplayFileProps,
      dragProps
    };
  },
  methods: {
    renderTrigger() {
      const h = this.$createElement;
      const getDefaultTrigger = () => {
        if (this.theme === "file-input") {
          return h(components_button_index.Button, helper.helper([{
            "attrs": {
              "disabled": this.innerDisabled,
              "variant": "outline"
            }
          }, this.triggerButtonProps]), [this.triggerUploadText]);
        }
        return h(components_button_index.Button, helper.helper([{
          "attrs": {
            "disabled": this.innerDisabled,
            "variant": "outline",
            "icon": () => h(iconsVue.UploadIcon)
          }
        }, this.triggerButtonProps]), [this.triggerUploadText]);
      };
      return utils_renderNode.renderContent(this, "default", "trigger") || getDefaultTrigger();
    },
    getNormalFileNode() {
      const h = this.$createElement;
      return h(components_upload_themes_normalFile["default"], helper.helper([{}, {
        "props": this.commonDisplayFileProps
      }, {
        "attrs": {
          "multiple": this.multiple
        },
        "scopedSlots": {
          fileListDisplay: this.$scopedSlots.fileListDisplay
        }
      }]), [h("div", {
        "class": `${this.classPrefix}-upload__trigger`,
        "on": {
          "click": this.triggerUpload
        }
      }, [this.renderTrigger()])]);
    },
    getSingleFileDraggerUploadNode() {
      const h = this.$createElement;
      return h(components_upload_themes_draggerFile["default"], helper.helper([{}, {
        "props": this.commonDisplayFileProps
      }, {
        "attrs": {
          "dragEvents": this.dragProps,
          "trigger": this.trigger,
          "cancelUpload": this.cancelUpload,
          "triggerUpload": this.triggerUpload,
          "uploadFiles": this.uploadFiles
        }
      }]));
    },
    getImageCardUploadNode() {
      const h = this.$createElement;
      return h(components_upload_themes_imageCard["default"], helper.helper([{}, {
        "props": this.commonDisplayFileProps
      }, {
        "attrs": {
          "multiple": this.multiple,
          "max": this.max,
          "showUploadProgress": this.showUploadProgress,
          "triggerUpload": this.triggerUpload,
          "uploadFiles": this.uploadFiles,
          "cancelUpload": this.cancelUpload
        }
      }, {
        "on": {
          preview: this.onInnerPreview
        }
      }]));
    },
    getFlowListNode() {
      const h = this.$createElement;
      return h(components_upload_themes_multipleFlowList["default"], helper.helper([{}, {
        "props": this.commonDisplayFileProps
      }, {
        "attrs": {
          "isBatchUpload": this.isBatchUpload,
          "draggable": this.draggable,
          "dragEvents": this.dragProps,
          "uploadFiles": this.uploadFiles,
          "cancelUpload": this.cancelUpload
        }
      }, {
        "on": {
          preview: this.onInnerPreview
        }
      }]), [h("div", {
        "class": `${this.classPrefix}-upload__trigger`,
        "on": {
          "click": this.triggerUpload
        }
      }, [this.renderTrigger()])]);
    },
    getCustomFile() {
      const h = this.$createElement;
      return h(components_upload_themes_customFile["default"], helper.helper([{}, {
        "props": this.commonDisplayFileProps
      }, {
        "attrs": {
          "draggable": this.draggable,
          "dragContent": this.dragContent,
          "dragEvents": this.dragProps,
          "triggerUpload": this.triggerUpload,
          "trigger": this.trigger,
          "childrenNode": this.$scopedSlots.default
        },
        "scopedSlots": {
          dragContent: this.$scopedSlots.dragContent,
          trigger: this.$scopedSlots.trigger
        }
      }]), [this.renderTrigger()]);
    }
  },
  render() {
    const h = arguments[0];
    return h("div", {
      "class": `${this.classPrefix}-upload`
    }, [h("input", {
      "ref": "inputRef",
      "attrs": {
        "type": "file",
        "disabled": this.innerDisabled,
        "multiple": this.multiple,
        "accept": this.accept,
        "hidden": true
      },
      "on": {
        "change": this.onNormalFileChange
      }
    }), ["file", "file-input"].includes(this.theme) && !this.draggable && this.getNormalFileNode(), ["file", "image"].includes(this.theme) && this.draggable && this.getSingleFileDraggerUploadNode(), this.theme === "image" && !this.draggable && this.getImageCardUploadNode(), ["image-flow", "file-flow"].includes(this.theme) && this.getFlowListNode(), this.theme === "custom" && this.getCustomFile(), this.tips && h("small", {
      "class": [this.tipsClasses, {
        [`${this.classPrefix}-upload__tips-${this.status}`]: this.status
      }]
    }, [this.tips])]);
  }
});

exports["default"] = _Upload;
//# sourceMappingURL=upload.js.map
