/**
 * ldesign v0.4.6
 * (c) 2023 ldesign
 * @license MIT
 */

import { h as helper } from '../_chunks/dep-b6ac6e96.js';
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { defineComponent, computed } from '@vue/composition-api';
import { UploadIcon } from '@ldesign/icons-vue';
import useFormDisabled from '../hooks/useFormDisabled.js';
import { Button } from '../button/index.js';
import { renderContent, renderTNodeJSX } from '../utils/render-tnode.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/useUpload.js';
import CustomFile from './themes/custom-file.js';
import '../utils/withInstall.js';
import 'vue';
import 'lodash/capitalize';
import '../button/button.js';
import '../loading/index.js';
import '../loading/directive.js';
import 'lodash/isObject';
import 'lodash/mapKeys';
import 'lodash/isEqual';
import '../loading/plugin.js';
import '../config.js';
import '../utils/dom.js';
import 'raf';
import 'lodash/isString';
import '../utils/easing.js';
import '../loading/loading.js';
import '../utils/transfer-dom.js';
import '../config-provider/config-receiver.js';
import 'lodash/mergeWith';
import '../config-provider/context.js';
import 'lodash/merge';
import '../_common/js/global-config/default-config.js';
import '../_common/js/global-config/locale/zh_CN.js';
import '@babel/runtime/helpers/typeof';
import '../_chunks/dep-2cb61c79.js';
import 'dayjs';
import '../utils/mixins.js';
import '../loading/props.js';
import '../loading/icon/gradient.js';
import '../_common/js/loading/circle-adapter.js';
import '../_common/js/utils/set-style.js';
import '../_common/js/utils/helper.js';
import '@babel/runtime/helpers/toConsumableArray';
import '@babel/runtime/helpers/objectWithoutProperties';
import '@babel/runtime/helpers/slicedToArray';
import 'lodash/isNull';
import 'lodash/isUndefined';
import 'lodash/isNumber';
import 'lodash/isArray';
import 'lodash/camelCase';
import 'lodash/kebabCase';
import '../utils/ripple.js';
import '../button/props.js';
import '../link/index.js';
import '../link/link.js';
import '../link/props.js';
import '../_common/js/upload/utils.js';
import '../_common/js/log/log.js';
import '../hooks/useGlobalIcon.js';
import '../config-provider/useConfig.js';
import './constants.js';
import '../hooks/useCommonClassName.js';
import './hooks/useDrag.js';
import '../image-viewer/index.js';
import '../image-viewer/image-viewer.js';
import '../hooks/useVModel.js';
import '../hooks/useDefaultValue.js';
import '../hooks/useConfig.js';
import '../utils/helper.js';
import '../image-viewer/props.js';
import '../image-viewer/base/Container.js';
import '../image-viewer/base/ImageModalIcon.js';
import '../hooks/tnode.js';
import 'lodash/isEmpty';
import 'lodash/isFunction';
import '../hooks/render-tnode.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/event.js';
import '../popup/container.js';
import '../popup/utils.js';
import '../popup/trigger.js';
import '../tooltip/props.js';
import '../image-viewer/utils.js';
import '../image-viewer/base/ImageItem.js';
import '../image-viewer/hooks.js';
import '../image-viewer/base/ImageViewerModal.js';
import '../dialog/index.js';
import '../dialog/dialog.js';
import 'lodash/throttle';
import '../hooks/useDestroyOnClose.js';
import '../_common/js/utils/getScrollbarWidth.js';
import '../dialog/stack.js';
import '../dialog/props.js';
import '../dialog/actions.js';
import '../dialog/plugin.js';
import '../config-provider/config-provider.js';
import 'lodash/cloneDeep';
import '../image-viewer/const.js';
import 'classnames';
import '../_common/js/upload/main.js';
import '@babel/runtime/helpers/toArray';
import '../_common/js/upload/xhr.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 _Upload = defineComponent({
  name: "TUpload",
  props: props,
  setup: function setup(props2, context) {
    var uploadData = useUpload(props2, context);
    var _useFormDisabled = useFormDisabled(),
      formDisabled = _useFormDisabled.formDisabled;
    var localeConfig = uploadData.localeConfig,
      classPrefix = uploadData.classPrefix,
      toUploadFiles = uploadData.toUploadFiles,
      displayFiles = uploadData.displayFiles,
      uploadValue = uploadData.uploadValue,
      sizeOverLimitMessage = uploadData.sizeOverLimitMessage,
      uploading = uploadData.uploading,
      tipsClasses = uploadData.tipsClasses,
      errorClasses = uploadData.errorClasses,
      placeholderClass = uploadData.placeholderClass,
      innerDisabled = uploadData.innerDisabled,
      onInnerRemove = uploadData.onInnerRemove,
      onDragFileChange = uploadData.onDragFileChange;
    var disabled = computed(function () {
      return formDisabled.value || innerDisabled.value;
    });
    var commonDisplayFileProps = computed(function () {
      return {
        files: uploadValue.value,
        toUploadFiles: toUploadFiles.value,
        displayFiles: displayFiles.value,
        theme: props2.theme,
        placeholder: props2.placeholder,
        disabled: disabled.value,
        tips: props2.tips,
        status: props2.status,
        sizeOverLimitMessage: sizeOverLimitMessage.value,
        uploading: uploading.value,
        classPrefix: classPrefix.value,
        tipsClasses: tipsClasses,
        errorClasses: errorClasses,
        placeholderClass: placeholderClass,
        locale: localeConfig.value,
        autoUpload: props2.autoUpload,
        showUploadProgress: props2.showUploadProgress,
        abridgeName: props2.abridgeName,
        fileListDisplay: props2.fileListDisplay,
        onRemove: onInnerRemove
      };
    });
    var dragProps = computed(function () {
      return {
        onDragFileChange: onDragFileChange,
        onDragenter: function 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: function 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: function 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);
        }
      };
    });
    var uploadClasses = computed(function () {
      return ["".concat(classPrefix.value, "-upload"), _defineProperty({}, "".concat(classPrefix.value, "-upload--theme-").concat(props2.theme), props2.theme === "file-input")];
    });
    return _objectSpread(_objectSpread({}, uploadData), {}, {
      commonDisplayFileProps: commonDisplayFileProps,
      dragProps: dragProps,
      uploadClasses: uploadClasses
    });
  },
  methods: {
    renderTrigger: function renderTrigger() {
      var _this = this;
      var h = this.$createElement;
      var getDefaultTrigger = function getDefaultTrigger() {
        if (_this.theme === "file-input") {
          return h(Button, helper([{
            "attrs": {
              "disabled": _this.disabled,
              "variant": "outline"
            }
          }, {
            "props": _this.triggerButtonProps
          }]), [_this.triggerUploadText]);
        }
        return h(Button, helper([{
          "attrs": {
            "disabled": _this.disabled,
            "variant": "outline",
            "icon": function icon() {
              return h(UploadIcon);
            }
          }
        }, {
          "props": _this.triggerButtonProps
        }]), [_this.triggerUploadText]);
      };
      return renderContent(this, "default", "trigger", {
        params: {
          dragActive: false,
          files: this.uploadValue
        }
      }) || getDefaultTrigger();
    },
    getNormalFileNode: function getNormalFileNode() {
      var h = this.$createElement;
      return h(NormalFile, helper([{}, {
        "props": this.commonDisplayFileProps
      }, {
        "attrs": {
          "multiple": this.multiple
        },
        "scopedSlots": {
          "fileListDisplay": this.$scopedSlots.fileListDisplay,
          "file-list-display": this.$scopedSlots["file-list-display"]
        }
      }]), [h("div", {
        "class": "".concat(this.classPrefix, "-upload__trigger"),
        "on": {
          "click": this.triggerUpload
        }
      }, [this.renderTrigger()])]);
    },
    getSingleFileDraggerUploadNode: function getSingleFileDraggerUploadNode() {
      var 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
        },
        "on": {
          "cancelUpload": this.innerCancelUpload
        },
        "scopedSlots": {
          "fileListDisplay": this.$scopedSlots.fileListDisplay,
          "file-list-display": this.$scopedSlots["file-list-display"]
        }
      }]));
    },
    getImageCardUploadNode: function getImageCardUploadNode() {
      var 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: function getFlowListNode() {
      var 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
        },
        "scopedSlots": {
          "fileListDisplay": this.$scopedSlots.fileListDisplay,
          "file-list-display": this.$scopedSlots["file-list-display"]
        }
      }]), [h("div", {
        "class": "".concat(this.classPrefix, "-upload__trigger"),
        "on": {
          "click": this.triggerUpload
        }
      }, [this.renderTrigger()])]);
    },
    getCustomFile: function getCustomFile() {
      var 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,
          "drag-content": this.$scopedSlots["drag-content"],
          "trigger": this.$scopedSlots.trigger
        }
      }]), [!this.draggable && this.renderTrigger()]);
    }
  },
  render: function render() {
    var h = arguments[0];
    return h("div", {
      "class": this.uploadClasses
    }, [h("input", helper([{
      "ref": "inputRef",
      "attrs": {
        "type": "file",
        "disabled": this.disabled,
        "multiple": this.multiple,
        "accept": this.accept,
        "hidden": true
      },
      "on": {
        "change": this.onNormalFileChange
      }
    }, {
      "attrs": this.inputAttributes
    }])), ["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(), Boolean(this.tips || this.$scopedSlots.tips) && h("small", {
      "class": [this.tipsClasses, _defineProperty({}, "".concat(this.classPrefix, "-upload__tips-").concat(this.status), this.status)]
    }, [renderTNodeJSX(this, "tips")])]);
  }
});

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