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

import { h as helper } from '../../chunks/helper.js';
import { defineComponent, computed } from '@vue/composition-api';
import { UploadIcon } from '@ldesign/icons-vue';
import { Button } from '../button/index.js';
import { renderContent } from '../../utils/render-node.js';
import props from './props.js';
import NormalFile from './themes/normal-file.js';
import DraggerFile from './themes/dragger-file.js';
import ImageCard from './themes/image-card.js';
import MultipleFlowList from './themes/multiple-flow-list.js';
import useUpload from './hooks/use-upload.js';
import CustomFile from './themes/custom-file.js';
import '../../chunks/_commonjsHelpers.js';
import '../../utils/with-install.js';
import 'vue';
import 'lodash';
import '../../config.js';
import '../button/button.js';
import '../loading/index.js';
import '../loading/loading.js';
import '../../utils/dom.js';
import 'raf';
import 'lodash/isString';
import '../../chunks/index.js';
import '../../chunks/log.js';
import '../../chunks/_commonjsHelpers-2e6815bd.js';
import '../../utils/easing.js';
import '../../utils/transfer-dom.js';
import '../config-provider/config-receiver.js';
import 'lodash/mergeWith';
import '../config-provider/context.js';
import '../../chunks/zh_CN.js';
import '../config-provider/type.js';
import '../../utils/mixins.js';
import '../loading/props.js';
import '../loading/icon/gradient.js';
import '../../chunks/defineProperty-838e4192.js';
import '../../chunks/set-style.js';
import '../../chunks/helper2.js';
import '../loading/style';
import '../loading/type.js';
import '../loading/plugin.js';
import '../../utils/ripple.js';
import '../button/props.js';
import '../button/style';
import '../button/type.js';
import '../../chunks/utils2.js';
import '../link/index.js';
import '../link/link.js';
import '../link/props.js';
import '../link/style';
import '../link/type.js';
import '../../hooks/use-global-icon.js';
import '../../hooks/use-config.js';
import '../config-provider/useConfig.js';
import './const.js';
import '../../hooks/use-common-classname.js';
import './hooks/use-drag.js';
import '../image-viewer/index.js';
import '../image-viewer/image-viewer.js';
import 'lodash/kebabCase';
import '../../hooks/use-default-value.js';
import '../image-viewer/props.js';
import '../image-viewer/base/ImageModalIcon.js';
import '../../hooks/lnode.js';
import 'lodash/isEmpty';
import 'lodash/isFunction';
import 'lodash/camelCase';
import '../../hooks/render-lnode.js';
import '../image-viewer/base/ImageViewerUtils.js';
import '../tooltip/index.js';
import '../../utils/map-props.js';
import '../tooltip/tooltip.js';
import '../popup/props.js';
import '../popup/popup.js';
import '@popperjs/core';
import '../../utils/helper.js';
import '../popup/container.js';
import '../tooltip/props.js';
import '../tooltip/style';
import '../tooltip/type.js';
import '../image-viewer/utils.js';
import '../image-viewer/base/ImageItem.js';
import '../image-viewer/hooks/index.js';
import '../image-viewer/base/ImageViewerModal.js';
import '../dialog/index.js';
import '../dialog/dialog.js';
import 'lodash/isNumber';
import 'lodash/throttle';
import '../../utils/event.js';
import '../../hooks/use-destroy-onclose.js';
import '../dialog/props.js';
import '../dialog/mixins/action.js';
import 'lodash/isObject';
import '../dialog/stack.js';
import '../dialog/style';
import '../dialog/type.js';
import '../dialog/plugin.js';
import '../image-viewer/const.js';
import '../image-viewer/base/Container.js';
import '../image-viewer/style';
import '../image-viewer/type.js';
import 'lodash/merge';
import '../../hooks/use-vmodel.js';

var _Upload = defineComponent({
  name: "LUpload",
  props,
  setup(props2, context) {
    const uploadData = useUpload(props2, context);
    const {
      localeConfig,
      classPrefix,
      toUploadFiles,
      displayFiles,
      uploadValue,
      sizeOverLimitMessage,
      uploading,
      tipsClasses,
      errorClasses,
      innerDisabled,
      onInnerRemove,
      onDragFileChange
    } = uploadData;
    const commonDisplayFileProps = 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 = 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(Button, helper([{
            "attrs": {
              "disabled": this.innerDisabled,
              "variant": "outline"
            }
          }, this.triggerButtonProps]), [this.triggerUploadText]);
        }
        return h(Button, helper([{
          "attrs": {
            "disabled": this.innerDisabled,
            "variant": "outline",
            "icon": () => h(UploadIcon)
          }
        }, this.triggerButtonProps]), [this.triggerUploadText]);
      };
      return renderContent(this, "default", "trigger") || getDefaultTrigger();
    },
    getNormalFileNode() {
      const h = this.$createElement;
      return h(NormalFile, 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(DraggerFile, 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(ImageCard, 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(MultipleFlowList, 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(CustomFile, 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])]);
  }
});

export { _Upload as default };
//# sourceMappingURL=upload.js.map
