import Vue from 'vue'

import { ModalController } from '../modal'
import { SaveFileFunction, ReadFileFunction, PrintFunction } from '../export'

import { VhbGlobalRenderer } from './renderer'
import { VhbGlobalInterceptor } from './interceptor'
import { VhbGlobalCommands } from './commands'
import { VhbGlobalFormats } from './formats'
import { VhbGlobalMenus } from './menus'
import { VhbGlobalSetup } from './setup'

export type VhbGlobalI18n = (key: string, args?: any) => number | string;
export type VhbGlobalTranslate = (key: string, args?: any) => string;
export type VhbGlobalUse = (plugin: VHBTablePluginObject, ...options: any[]) => VHBTableCore;

export const setup: VhbGlobalSetup
export const interceptor: VhbGlobalInterceptor
export const renderer: VhbGlobalRenderer
export const commands: VhbGlobalCommands
export const formats: VhbGlobalFormats
export const menus: VhbGlobalMenus
export const modal: ModalController
export const saveFile: SaveFileFunction
export const readFile: ReadFileFunction
export const print: PrintFunction
export const t: VhbGlobalI18n
export const _t: VhbGlobalTranslate
export const use: VhbGlobalUse

export interface VHBTablePluginObject {
  install(vhbtable: VHBTableCore, ...options: any[]): void;
  [key: string]: any;
}

export type VHBTableVersion = 'v1' | 'v2' | 'v3' | 'v4'

export const v: VHBTableVersion

export interface VHBTableCore {
  /**
   * 已被 version 替换
   * @deprecated
   */
  v: VHBTableVersion;
  /**
   * 版本号
   */
  version: string;
  /**
   * 设置全局参数/获取所有参数
   */
  setup: VhbGlobalSetup;
  /**
   * Table interceptor
   */
  interceptor: VhbGlobalInterceptor;
  /**
   * Table renderer
   */
  renderer: VhbGlobalRenderer;
  /**
   * Table commands
   */
  commands: VhbGlobalCommands;
  /**
   * Table column formatter
   */
  formats: VhbGlobalFormats;
  /**
   * Table context menu
   */
  menus: VhbGlobalMenus;
  /**
   * 弹窗
   */
  modal: ModalController;
  /**
   * 读取本地文件
   */
  saveFile: SaveFileFunction;
  /**
   * 读取本地文件
   */
  readFile: ReadFileFunction;
  /**
   * 打印
   */
  print: PrintFunction;
  /**
   * 安装插件
   * @param plugin
   * @param options
   */
  use: VhbGlobalUse;
  /**
   * 读取内置国际化
   */
  t: VhbGlobalI18n;
  _t: VhbGlobalTranslate;
}

/**
 * 一个基于 vue 的 PC 端表格组件，支持增删改查、虚拟滚动、懒加载、快捷菜单、数据校验、树形结构、打印导出、表单渲染、数据分页、虚拟列表、弹窗、自定义模板、渲染器、贼灵活的配置项、扩展接口等...
 */
export const VHBTable: VHBTableCore

export * from './renderer'
export * from './interceptor'
export * from './commands'
export * from './formats'
export * from './menus'
export * from './setup'

export default VHBTable
