import { defineComponent, createVNode, Fragment } from 'vue';
import { useTheme } from '../_theme/useTheme';
import Trigger from './trigger.js';
import FileList from './fileList.js';
import useUpload from './useUpload';

const uploadProps = {
  accept: {
    type: Array,
    default: () => []
  },
  action: String,
  headers: {
    type: Object,
    default: () => ({})
  },
  data: {
    type: Object,
    default: () => ({})
  },
  withCredentials: {
    type: Boolean,
    default: false
  },
  timeout: {
    type: Number
  },
  beforeUpload: Function,
  beforeRemove: Function,
  disabled: {
    type: Boolean,
    default: false
  },
  fileList: {
    type: Array,
    default: () => []
  },
  listType: {
    type: String,
    default: 'text'
  },
  multiple: {
    type: Boolean,
    default: false
  },
  multipleLimit: Number,
  name: {
    type: String,
    default: 'file'
  },
  showFileList: {
    type: Boolean,
    default: true
  },
  httpRequest: {
    type: Function
  },
  transformResponse: Function
};
var upload = defineComponent({
  name: 'FUpload',
  props: uploadProps,
  emits: ['change', 'remove', 'success', 'error', 'progress', 'exceed', 'update:fileList'],
  setup(props, ctx) {
    var _expose, _ref;
    useTheme();
    const {
      uploadFiles,
      isDragger,
      clearFiles,
      addFile,
      removeFile
    } = useUpload(props, ctx.emit);
    const getFileList = () => {
      if (!props.showFileList) {
        return null;
      }
      const fileListSlots = ctx.slots.fileList;
      if (!fileListSlots) {
        const file = ctx.slots.file;
        return createVNode(FileList, null, {
          file
        });
      }
      return fileListSlots({
        uploadFiles: uploadFiles.value
      });
    };
    (_expose = (_ref = ctx).expose) === null || _expose === void 0 || _expose.call(_ref, {
      clearFiles,
      addFile,
      removeFile
    });
    return () => {
      var _ctx$slots$default, _ctx$slots, _ctx$slots$tip, _ctx$slots2;
      return createVNode(Fragment, null, [ctx.slots.default ? createVNode(Trigger, {
        "class": isDragger.value && 'is-dragger'
      }, {
        default: () => [(_ctx$slots$default = (_ctx$slots = ctx.slots).default) === null || _ctx$slots$default === void 0 ? void 0 : _ctx$slots$default.call(_ctx$slots, {
          uploadFiles: uploadFiles.value
        })]
      }) : createVNode(Trigger, {
        "class": isDragger.value && 'is-dragger'
      }, null), (_ctx$slots$tip = (_ctx$slots2 = ctx.slots).tip) === null || _ctx$slots$tip === void 0 ? void 0 : _ctx$slots$tip.call(_ctx$slots2), getFileList()]);
    };
  }
});

export { upload as default, uploadProps };
