import { App, createApp } from "vue";
import MainApp from "./App.vue";
// reset style sheet
import "@/styles/index.scss";
// CSS common style sheet
import "@/styles/common.scss";
// iconfont css
import "@/assets/iconfont/iconfont.css";
// import "@/assets/iconfont/iconfont.js";
// font css
import "@/assets/fonts/font.scss";
// element css
import "element-plus/dist/index.css";
// element dark css
import "element-plus/theme-chalk/dark/css-vars.css";
// custom element dark css
import "@/styles/theme/element-dark.scss";
// custom element css
import "@/styles/element.scss";
import "@vue-office/docx/lib/index.css";
import "@vue-office/excel/lib/index.css";
// postcss-pxtorem
// import "@/utils/rem";
// svg icons
import "virtual:svg-icons-register";
// element plus
// import ElementPlus from "element-plus";
// element icons
// import * as Icons from "@element-plus/icons-vue";
// custom directives
import directives from "@/directives/index";
// vue Router
import router from "@/routers";
// vue i18n
import I18n from "@/languages/index";
// pinia store
import pinia from "@/stores";
// errorHandler
import errorHandler from "@/utils/errorHandler";

import Toast from "vue-toastification";
// import "vue-toastification/dist/index.css";
import "@/styles/var/toastification.scss";
// vant css
import "vant/lib/tabs/style";
import "vant/lib/tab/style";
import "vant/lib/cell/style";
import "vant/lib/cell-group/style";
import "vant/lib/empty/style";

// 打印模块
import { hiPrintPlugin } from "vue-plugin-hiprint";

import {
  ElAutocomplete,
  ElBacktop,
  ElBadge,
  ElImage,
  ElImageViewer,
  ElInput,
  ElInputNumber,
  ElDatePicker,
  ElSelect,
  ElSelectV2,
  ElTreeSelect,
  ElSwitch,
  ElStatistic,
  ElCheckbox,
  ElCheckboxGroup,
  ElCheckboxButton,
  ElNotification,
  ElProgress,
  ElRadio,
  ElRadioButton,
  ElRadioGroup,
  ElResult,
  ElSpace,
  ElText,
  ElTag,
  ElCheckTag,
  ElTimeline,
  ElTimelineItem,
  ElUpload
} from "element-plus";

// vxe-table
// import XEUtils from "xe-utils";

import {
  // 全局对象
  VXETable,

  // 表格功能
  Filter,
  Edit,
  Menu,
  Export,
  Keyboard,
  Validator,

  // 可选组件
  Icon,
  Column,
  Colgroup,
  Grid,
  Tooltip,
  Toolbar,
  Pager,
  Form,
  FormItem,
  FormGather,
  Checkbox,
  CheckboxGroup,
  Radio,
  RadioGroup,
  RadioButton,
  Switch,
  Input,
  Select,
  Optgroup,
  Option,
  Textarea,
  Button,
  Modal,
  List,
  Pulldown,

  // 表格
  Table
} from "vxe-table";
// import "vxe-table/styles/variable.scss";
// import "vxe-table/styles/cssvar.scss";
// import "vxe-table/lib/style.css";
import "@/styles/var/vxe-variable.scss";
import "@/styles/var/vant-variable.scss";

import { Tab as VanTab, Tabs as VanTabs, Cell, CellGroup, Empty as VanEmpty } from "vant";

// 按需加载的方式默认是不带国际化的，自定义国际化需要自行解析占位符 '{0}'，例如：
VXETable.setup({
  // @ts-ignore
  i18n: (key, args) => I18n.global.t(key, args),
  // 重置vxetable的图标
  icon: {
    TABLE_FILTER_NONE: "iconfont iconfilter-funnel-01",
    TABLE_FILTER_MATCH: "iconfont iconfilter-funnel-01-fill"
  }
});

import "@/components/LjVxeTable/interface/plugins.tsx";

function useTable(app: App) {
  // 表格功能
  app.use(Filter).use(Edit).use(Menu).use(Export).use(Keyboard).use(Validator);

  // 可选组件
  app
    .use(Icon)
    .use(Column)
    .use(Colgroup)
    .use(Grid)
    .use(Tooltip)
    .use(Toolbar)
    .use(Pager)
    .use(Form)
    .use(FormItem)
    .use(FormGather)
    .use(Checkbox)
    .use(CheckboxGroup)
    .use(Radio)
    .use(RadioGroup)
    .use(RadioButton)
    .use(Switch)
    .use(Input)
    .use(Select)
    .use(Optgroup)
    .use(Option)
    .use(Textarea)
    .use(Button)
    .use(Modal)
    .use(List)
    .use(Pulldown)

    // 安装表格
    .use(Table);
}

// import VXETable from "vxe-table";
// import "vxe-table/lib/style.css";

// // 按需加载的方式默认是不带国际化的，自定义国际化需要自行解析占位符 '{0}'，例如：
// VXETable.setup({
//   i18n: (key, args) => I18n.global.t(key, args)
// });

// function useTable(app: App) {
//   app.use(VXETable);
// }

const app = createApp(MainApp);

app.config.errorHandler = errorHandler;

// app.config.globalProperties.$toast = Toast;

app.use(Toast, {
  transition: "Vue-Toastification__fade",
  maxToasts: 20,
  newestOnTop: true,
  position: "top-right",
  timeout: 5000,
  closeOnClick: false,
  pauseOnFocusLoss: true,
  pauseOnHover: true,
  draggable: true,
  // draggablePercent: 0.6,
  showCloseButtonOnHover: false,
  hideProgressBar: false,
  closeButton: "button",
  icon: true,
  rtl: false
});
// register the element Icons component
// Object.keys(Icons).forEach(key => {
//   app.component(key, Icons[key as keyof typeof Icons]);
// });

app.use(directives).use(router).use(I18n).use(pinia).mount("#app");

app.use(useTable);
app.use(hiPrintPlugin);
hiPrintPlugin.install(app);
// hiPrintPlugin.disAutoConnect();

app.use(ElAutocomplete);
app.use(ElBacktop);
app.use(ElBadge);
app.use(ElDatePicker);
app.use(ElImage);
app.use(ElImageViewer);
app.use(ElInput);
app.use(ElInputNumber);
app.use(ElSelect);
app.use(ElSelectV2);
app.use(ElTreeSelect);
app.use(ElSwitch);
app.use(ElStatistic);
app.use(ElCheckbox);
app.use(ElCheckboxGroup);
app.use(ElCheckboxButton);
app.use(ElNotification);
app.use(ElProgress);
app.use(ElRadio);
app.use(ElRadioButton);
app.use(ElRadioGroup);
app.use(ElResult);
app.use(ElSpace);
app.use(ElText);
app.use(ElTag);
app.use(ElCheckTag);
app.use(ElTimeline);
app.use(ElTimelineItem);
app.use(ElUpload);
// vant init
app.use(VanTabs);
app.use(VanTab);
app.use(Cell);
app.use(CellGroup);
app.use(VanEmpty);

// 引入函数式弹窗
import Dialog from "@/utils/dialog";
// 挂载到app
app.config.globalProperties.$dialog = Dialog;
