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

'use strict';

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

var helper = require('../_chunks/dep-c3e1ffac.js');
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var VueCompositionAPI = require('@vue/composition-api');
var iconsVue = require('@ldesign/icons-vue');
var hooks_useFormDisabled = require('../hooks/useFormDisabled.js');
var button_index = require('../button/index.js');
var utils_renderTnode = require('../utils/render-tnode.js');
var upload_props = require('./props.js');
var upload_themes_normalFile = require('./themes/normal-file.js');
var upload_themes_draggerFile = require('./themes/dragger-file.js');
var upload_themes_imageCard = require('./themes/image-card.js');
var upload_themes_multipleFlowList = require('./themes/multiple-flow-list.js');
var upload_hooks_useUpload = require('./hooks/useUpload.js');
var upload_themes_customFile = require('./themes/custom-file.js');
require('../utils/withInstall.js');
require('vue');
require('lodash/capitalize');
require('../button/button.js');
require('../loading/index.js');
require('../loading/directive.js');
require('lodash/isObject');
require('lodash/mapKeys');
require('lodash/isEqual');
require('../loading/plugin.js');
require('../config.js');
require('../utils/dom.js');
require('raf');
require('lodash/isString');
require('../utils/easing.js');
require('../loading/loading.js');
require('../utils/transfer-dom.js');
require('../config-provider/config-receiver.js');
require('lodash/mergeWith');
require('../config-provider/context.js');
require('lodash/merge');
require('../_common/js/global-config/default-config.js');
require('../_common/js/global-config/locale/zh_CN.js');
require('@babel/runtime/helpers/typeof');
require('../_chunks/dep-7c884501.js');
require('dayjs');
require('../utils/mixins.js');
require('../loading/props.js');
require('../loading/icon/gradient.js');
require('../_common/js/loading/circle-adapter.js');
require('../_common/js/utils/set-style.js');
require('../_common/js/utils/helper.js');
require('@babel/runtime/helpers/toConsumableArray');
require('@babel/runtime/helpers/objectWithoutProperties');
require('@babel/runtime/helpers/slicedToArray');
require('lodash/isNull');
require('lodash/isUndefined');
require('lodash/isNumber');
require('lodash/isArray');
require('lodash/camelCase');
require('lodash/kebabCase');
require('../utils/ripple.js');
require('../button/props.js');
require('../link/index.js');
require('../link/link.js');
require('../link/props.js');
require('../_common/js/upload/utils.js');
require('../_common/js/log/log.js');
require('../hooks/useGlobalIcon.js');
require('../config-provider/useConfig.js');
require('./constants.js');
require('../hooks/useCommonClassName.js');
require('./hooks/useDrag.js');
require('../image-viewer/index.js');
require('../image-viewer/image-viewer.js');
require('../hooks/useVModel.js');
require('../hooks/useDefaultValue.js');
require('../hooks/useConfig.js');
require('../utils/helper.js');
require('../image-viewer/props.js');
require('../image-viewer/base/Container.js');
require('../image-viewer/base/ImageModalIcon.js');
require('../hooks/tnode.js');
require('lodash/isEmpty');
require('lodash/isFunction');
require('../hooks/render-tnode.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/event.js');
require('../popup/container.js');
require('../popup/utils.js');
require('../popup/trigger.js');
require('../tooltip/props.js');
require('../image-viewer/utils.js');
require('../image-viewer/base/ImageItem.js');
require('../image-viewer/hooks.js');
require('../image-viewer/base/ImageViewerModal.js');
require('../dialog/index.js');
require('../dialog/dialog.js');
require('lodash/throttle');
require('../hooks/useDestroyOnClose.js');
require('../_common/js/utils/getScrollbarWidth.js');
require('../dialog/stack.js');
require('../dialog/props.js');
require('../dialog/actions.js');
require('../dialog/plugin.js');
require('../config-provider/config-provider.js');
require('lodash/cloneDeep');
require('../image-viewer/const.js');
require('classnames');
require('../_common/js/upload/main.js');
require('@babel/runtime/helpers/toArray');
require('../_common/js/upload/xhr.js');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);

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__default["default"](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 = VueCompositionAPI.defineComponent({
  name: "TUpload",
  props: upload_props["default"],
  setup: function setup(props2, context) {
    var uploadData = upload_hooks_useUpload["default"](props2, context);
    var _useFormDisabled = hooks_useFormDisabled["default"](),
      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 = VueCompositionAPI.computed(function () {
      return formDisabled.value || innerDisabled.value;
    });
    var commonDisplayFileProps = VueCompositionAPI.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 = VueCompositionAPI.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 = VueCompositionAPI.computed(function () {
      return ["".concat(classPrefix.value, "-upload"), _defineProperty__default["default"]({}, "".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_index.Button, helper.helper([{
            "attrs": {
              "disabled": _this.disabled,
              "variant": "outline"
            }
          }, {
            "props": _this.triggerButtonProps
          }]), [_this.triggerUploadText]);
        }
        return h(button_index.Button, helper.helper([{
          "attrs": {
            "disabled": _this.disabled,
            "variant": "outline",
            "icon": function icon() {
              return h(iconsVue.UploadIcon);
            }
          }
        }, {
          "props": _this.triggerButtonProps
        }]), [_this.triggerUploadText]);
      };
      return utils_renderTnode.renderContent(this, "default", "trigger", {
        params: {
          dragActive: false,
          files: this.uploadValue
        }
      }) || getDefaultTrigger();
    },
    getNormalFileNode: function getNormalFileNode() {
      var h = this.$createElement;
      return h(upload_themes_normalFile["default"], helper.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(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
        },
        "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(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: function getFlowListNode() {
      var h = this.$createElement;
      return h(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
        },
        "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(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,
          "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.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__default["default"]({}, "".concat(this.classPrefix, "-upload__tips-").concat(this.status), this.status)]
    }, [utils_renderTnode.renderTNodeJSX(this, "tips")])]);
  }
});

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