/**
 * Vue File Uploader 组件入口文件
 * 支持 Vue 2.x 和 Vue 3.x
 */

import { isVue2, install as installVueDemi } from 'vue-demi'
import type { App } from 'vue'
import FileUploader from './components/FileUploader.vue'
import type { FileUploaderProps, UploadFile, UploadStatus } from './types'

// 确保 vue-demi 已安装
installVueDemi()

// 导出独立组件，用于局部注册
export { FileUploader }
export type { FileUploaderProps, UploadFile, UploadStatus }

/**
 * Vue 插件安装函数
 * 用于全局注册组件
 * @param app Vue 应用实例
 */
const install = (app: App): void => {
  if (isVue2) {
    // Vue 2.x
    const Vue = app as any
    Vue.component('FileUploader', FileUploader)
  } else {
    // Vue 3.x
    app.component('FileUploader', FileUploader)
  }
}

// 导出 Vue 插件
export default {
  install,
  FileUploader
}

// 导出类型定义
export * from './types'

// 自动安装（用于 CDN 引入场景）
declare global {
  interface Window {
    Vue?: App
  }
}

if (typeof window !== 'undefined' && window.Vue) {
  install(window.Vue)
} 