import type { App } from 'vue';

import {
  VxeButton,
  VxeButtonGroup,
  VxeDrawer,
  VxeForm,
  VxeFormDesign,
  VxeFormGather,
  VxeFormItem,
  VxeFormView,
  VxeIcon,
  VxeInput,
  VxeNumberInput,
  VxeDatePanel,
  VxeDatePicker,
  VxeList,
  VxeLoading,
  VxeModal,
  VxePager,
  VxeRadio,
  VxeRadioGroup,
  VxeCheckbox,
  VxeCheckboxGroup,
  VxeSelect,
  VxeSwitch,
  VxeTooltip,
  VxeTree,
  VxeTreeSelect,
  VxeUI,
  VxeRow,
  VxeCol,
  VxeDateRangePicker,
} from 'vxe-pc-ui';

import zhCN from 'vxe-pc-ui/lib/language/zh-CN';

import { VxeColgroup, VxeColumn, VxeGrid, VxeTable, VxeToolbar } from 'vxe-table';


function LazyVxeUIForForm(app: App) {
  app.use(VxeForm);
  app.use(VxeFormDesign);
  app.use(VxeFormGather);
  app.use(VxeFormItem);
  app.use(VxeFormView);
  app.use(VxeInput);
  app.use(VxeNumberInput);
  app.use(VxeDatePanel);
  app.use(VxeDatePicker);
  app.use(VxeDateRangePicker);
  app.use(VxeRadio);
  app.use(VxeSwitch);
  app.use(VxeSelect);
  app.use(VxeTreeSelect);
  app.use(VxeTree);
  app.use(VxeRadioGroup);
  app.use(VxeCheckbox);
  app.use(VxeCheckboxGroup);

  app.use(VxeList);


  app.use(VxeButton);
  app.use(VxeButtonGroup);
  app.use(VxeIcon);
  app.use(VxeLoading);
  // 分页
  app.use(VxePager);
  app.use(VxeRow);
  app.use(VxeCol);

  app.use(VxeModal);
  app.use(VxeDrawer);
  app.use(VxeTooltip);
  // app.use(VxeTable);
  // app.use(VxeColumn);
  // app.use(VxeGrid);
  // app.use(VxeToolbar);
}

function LazyVxeUIForTable(app: App) {
  app.use(VxeTable);
  app.use(VxeColumn);
  app.use(VxeColgroup);
  app.use(VxeGrid);
  app.use(VxeToolbar);
}

export function createVxe(options?: Record<string, any>) {
  VxeUI.setI18n('zh-CN', zhCN);
  VxeUI.setLanguage('zh-CN');
  return {
    install: (app: App) => {
      LazyVxeUIForForm(app);
      LazyVxeUIForTable(app);
    },
  };
}
