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

'use strict';

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

var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var vue = require('vue');
var iconsVueNext = require('@ldesign/icons-vue-next');
var button_index = require('../button/index.js');
var hooks_tnode = require('../hooks/tnode.js');
var form_hooks = require('../form/hooks.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('../button/button.js');
require('@babel/runtime/helpers/toConsumableArray');
require('../loading/index.js');
require('../loading/directive.js');
require('../loading/plugin.js');
require('../utils/dom.js');
require('../_chunks/dep-f4db2590.js');
require('lodash/isString');
require('lodash/isFunction');
require('lodash/isArray');
require('../utils/easing.js');
require('../hooks/useConfig.js');
require('../config-provider/useConfig.js');
require('lodash/cloneDeep');
require('../config-provider/context.js');
require('lodash/mergeWith');
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('dayjs');
require('../loading/loading.js');
require('@babel/runtime/helpers/slicedToArray');
require('../utils/render-tnode.js');
require('lodash/isEmpty');
require('lodash/isObject');
require('lodash/camelCase');
require('lodash/kebabCase');
require('../hooks/useTeleport.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/objectWithoutProperties');
require('lodash/isNull');
require('lodash/isUndefined');
require('lodash/isNumber');
require('../hooks/useRipple.js');
require('../utils/set-style.js');
require('../hooks/useKeepAnimation.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('./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('../image-viewer/props.js');
require('../image-viewer/base/ImageModalIcon.js');
require('../image-viewer/base/ImageViewerUtils.js');
require('../tooltip/index.js');
require('../tooltip/tooltip.js');
require('lodash/omit');
require('../popup/props.js');
require('../popup/index.js');
require('../popup/popup.js');
require('@popperjs/core');
require('../popup/container.js');
require('../hooks/useResizeObserver.js');
require('../tooltip/util.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('../hooks/useDestroyOnClose.js');
require('../_common/js/utils/getScrollbarWidth.js');
require('../dialog/stack.js');
require('../dialog/hooks.js');
require('../dialog/props.js');
require('../dialog/plugin.js');
require('../image-viewer/const.js');
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 = vue.defineComponent({
  name: "TUpload",
  props: upload_props["default"],
  setup: function setup(props2, _ref) {
    var slots = _ref.slots,
      expose = _ref.expose;
    var renderContent = hooks_tnode.useContent();
    var renderTNodeJSX = hooks_tnode.useTNodeJSX();
    var _useUpload = upload_hooks_useUpload["default"](props2),
      locale = _useUpload.locale,
      classPrefix = _useUpload.classPrefix,
      triggerUploadText = _useUpload.triggerUploadText,
      toUploadFiles = _useUpload.toUploadFiles,
      displayFiles = _useUpload.displayFiles,
      uploadValue = _useUpload.uploadValue,
      sizeOverLimitMessage = _useUpload.sizeOverLimitMessage,
      uploading = _useUpload.uploading,
      tipsClasses = _useUpload.tipsClasses,
      errorClasses = _useUpload.errorClasses,
      placeholderClass = _useUpload.placeholderClass,
      inputRef = _useUpload.inputRef,
      onInnerRemove = _useUpload.onInnerRemove,
      uploadFiles = _useUpload.uploadFiles,
      onNormalFileChange = _useUpload.onNormalFileChange,
      onDragFileChange = _useUpload.onDragFileChange,
      triggerUpload = _useUpload.triggerUpload,
      cancelUpload = _useUpload.cancelUpload;
    var disabled = form_hooks.useFormDisabled();
    expose({
      upload: inputRef.value,
      uploading: uploading,
      triggerUpload: triggerUpload,
      uploadFiles: uploadFiles,
      cancelUpload: cancelUpload
    });
    var renderTrigger = function renderTrigger() {
      var getDefaultTrigger = function getDefaultTrigger() {
        if (props2.theme === "file-input") {
          return vue.createVNode(button_index.Button, vue.mergeProps({
            "disabled": disabled.value,
            "variant": "outline"
          }, props2.triggerButtonProps), {
            "default": function _default() {
              return [triggerUploadText.value];
            }
          });
        }
        return vue.createVNode(button_index.Button, vue.mergeProps({
          "disabled": disabled.value,
          "variant": "outline",
          "icon": function icon() {
            return vue.createVNode(iconsVueNext.UploadIcon, null, null);
          }
        }, props2.triggerButtonProps), {
          "default": function _default() {
            return [triggerUploadText.value];
          }
        });
      };
      return renderContent("default", "trigger", {
        params: {
          dragActive: false,
          files: uploadValue.value
        }
      }) || getDefaultTrigger();
    };
    var commonDisplayFileProps = vue.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: locale.value,
        autoUpload: props2.autoUpload,
        abridgeName: props2.abridgeName,
        showUploadProgress: props2.showUploadProgress,
        fileListDisplay: props2.fileListDisplay,
        onRemove: onInnerRemove
      };
    });
    var dragProps = {
      onDragFileChange: onDragFileChange,
      onDragenter: props2.onDragenter,
      onDragleave: props2.onDragleave,
      onDrop: props2.onDrop
    };
    var getNormalFileNode = function getNormalFileNode() {
      return vue.createVNode(upload_themes_normalFile["default"], vue.mergeProps(commonDisplayFileProps.value, {
        "multiple": props2.multiple
      }), {
        "default": function _default() {
          return [vue.createVNode("div", {
            "class": "".concat(classPrefix.value, "-upload__trigger"),
            "onClick": triggerUpload
          }, [renderTrigger()])];
        },
        "fileListDisplay": slots.fileListDisplay,
        "file-list-display": slots["file-list-display"]
      });
    };
    var getSingleFileDraggerUploadNode = function getSingleFileDraggerUploadNode() {
      return vue.createVNode(upload_themes_draggerFile["default"], vue.mergeProps(commonDisplayFileProps.value, {
        "dragEvents": dragProps,
        "trigger": props2.trigger,
        "cancelUpload": cancelUpload,
        "triggerUpload": triggerUpload,
        "uploadFiles": uploadFiles,
        "onCancelUpload": props2.onCancelUpload
      }), {
        "fileListDisplay": slots.fileListDisplay,
        "file-list-display": slots["file-list-display"]
      });
    };
    var getImageCardUploadNode = function getImageCardUploadNode() {
      return vue.createVNode(upload_themes_imageCard["default"], vue.mergeProps(commonDisplayFileProps.value, {
        "multiple": props2.multiple,
        "max": props2.max,
        "showUploadProgress": props2.showUploadProgress,
        "triggerUpload": triggerUpload,
        "uploadFiles": uploadFiles,
        "cancelUpload": cancelUpload,
        "onPreview": props2.onPreview
      }), null);
    };
    var getFlowListNode = function getFlowListNode() {
      return vue.createVNode(upload_themes_multipleFlowList["default"], vue.mergeProps(commonDisplayFileProps.value, {
        "isBatchUpload": props2.isBatchUpload,
        "draggable": props2.draggable,
        "dragEvents": dragProps,
        "uploadFiles": uploadFiles,
        "cancelUpload": cancelUpload,
        "onPreview": props2.onPreview
      }), {
        "default": function _default() {
          return [vue.createVNode("div", {
            "class": "".concat(classPrefix.value, "-upload__trigger"),
            "onClick": triggerUpload
          }, [!props2.draggable && renderTrigger()])];
        },
        "fileListDisplay": slots.fileListDisplay,
        "file-list-display": slots["file-list-display"]
      });
    };
    var getCustomFile = function getCustomFile() {
      return vue.createVNode(upload_themes_customFile["default"], vue.mergeProps(commonDisplayFileProps.value, {
        "draggable": props2.draggable,
        "dragContent": props2.dragContent,
        "dragEvents": dragProps,
        "triggerUpload": triggerUpload,
        "trigger": props2.trigger,
        "childrenNode": slots["default"]
      }), {
        "default": function _default() {
          return [renderTrigger()];
        },
        "dragContent": slots.dragContent,
        "drag-content": slots["drag-content"],
        "trigger": slots.trigger
      });
    };
    return function () {
      return vue.createVNode("div", {
        "class": "".concat(classPrefix.value, "-upload")
      }, [vue.createVNode("input", vue.mergeProps({
        "ref": inputRef,
        "type": "file",
        "disabled": disabled.value,
        "onChange": onNormalFileChange,
        "multiple": props2.multiple,
        "accept": props2.accept,
        "hidden": true
      }, props2.inputAttributes ? _objectSpread({}, props2.inputAttributes) : {}), null), ["file", "file-input"].includes(props2.theme) && !props2.draggable && getNormalFileNode(), ["file", "image"].includes(props2.theme) && props2.draggable && getSingleFileDraggerUploadNode(), props2.theme === "image" && !props2.draggable && getImageCardUploadNode(), ["image-flow", "file-flow"].includes(props2.theme) && getFlowListNode(), props2.theme === "custom" && getCustomFile(), Boolean(props2.tips || slots.tips) && vue.createVNode("small", {
        "class": [tipsClasses, _defineProperty__default["default"]({}, "".concat(classPrefix.value, "-upload__tips-").concat(props2.status), props2.status)]
      }, [renderTNodeJSX("tips")])]);
    };
  }
});

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