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

import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { defineComponent, computed, createVNode, mergeProps } from 'vue';
import { UploadIcon } from '@ldesign/icons-vue-next';
import { Button } from '../button/index.js';
import { useContent, useTNodeJSX } from '../hooks/tnode.js';
import { useFormDisabled } from '../form/hooks.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 '../button/button.js';
import '@babel/runtime/helpers/toConsumableArray';
import '../loading/index.js';
import '../loading/directive.js';
import '../loading/plugin.js';
import '../utils/dom.js';
import '../_chunks/dep-e041f5b0.js';
import 'lodash/isString';
import 'lodash/isFunction';
import 'lodash/isArray';
import '../utils/easing.js';
import '../hooks/useConfig.js';
import '../config-provider/useConfig.js';
import 'lodash/cloneDeep';
import '../config-provider/context.js';
import 'lodash/mergeWith';
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 'dayjs';
import '../loading/loading.js';
import '@babel/runtime/helpers/slicedToArray';
import '../utils/render-tnode.js';
import 'lodash/isEmpty';
import 'lodash/isObject';
import 'lodash/camelCase';
import 'lodash/kebabCase';
import '../hooks/useTeleport.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/objectWithoutProperties';
import 'lodash/isNull';
import 'lodash/isUndefined';
import 'lodash/isNumber';
import '../hooks/useRipple.js';
import '../utils/set-style.js';
import '../hooks/useKeepAnimation.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 './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 '../image-viewer/props.js';
import '../image-viewer/base/ImageModalIcon.js';
import '../image-viewer/base/ImageViewerUtils.js';
import '../tooltip/index.js';
import '../tooltip/tooltip.js';
import 'lodash/omit';
import '../popup/props.js';
import '../popup/index.js';
import '../popup/popup.js';
import '@popperjs/core';
import '../popup/container.js';
import '../hooks/useResizeObserver.js';
import '../tooltip/util.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 '../hooks/useDestroyOnClose.js';
import '../_common/js/utils/getScrollbarWidth.js';
import '../dialog/stack.js';
import '../dialog/hooks.js';
import '../dialog/props.js';
import '../dialog/plugin.js';
import '../image-viewer/const.js';
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, _ref) {
    var slots = _ref.slots,
      expose = _ref.expose;
    var renderContent = useContent();
    var renderTNodeJSX = useTNodeJSX();
    var _useUpload = useUpload(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 = 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 createVNode(Button, mergeProps({
            "disabled": disabled.value,
            "variant": "outline"
          }, props2.triggerButtonProps), {
            "default": function _default() {
              return [triggerUploadText.value];
            }
          });
        }
        return createVNode(Button, mergeProps({
          "disabled": disabled.value,
          "variant": "outline",
          "icon": function icon() {
            return createVNode(UploadIcon, null, null);
          }
        }, props2.triggerButtonProps), {
          "default": function _default() {
            return [triggerUploadText.value];
          }
        });
      };
      return renderContent("default", "trigger", {
        params: {
          dragActive: false,
          files: uploadValue.value
        }
      }) || getDefaultTrigger();
    };
    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: 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 createVNode(NormalFile, mergeProps(commonDisplayFileProps.value, {
        "multiple": props2.multiple
      }), {
        "default": function _default() {
          return [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 createVNode(DraggerFile, 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 createVNode(ImageCard, 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 createVNode(MultipleFlowList, mergeProps(commonDisplayFileProps.value, {
        "isBatchUpload": props2.isBatchUpload,
        "draggable": props2.draggable,
        "dragEvents": dragProps,
        "uploadFiles": uploadFiles,
        "cancelUpload": cancelUpload,
        "onPreview": props2.onPreview
      }), {
        "default": function _default() {
          return [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 createVNode(CustomFile, 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 createVNode("div", {
        "class": "".concat(classPrefix.value, "-upload")
      }, [createVNode("input", 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) && createVNode("small", {
        "class": [tipsClasses, _defineProperty({}, "".concat(classPrefix.value, "-upload__tips-").concat(props2.status), props2.status)]
      }, [renderTNodeJSX("tips")])]);
    };
  }
});

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