import { createApp } from 'vue'
import { createPinia } from 'pinia'

import tableAutoScroll from './directive/tableScroll/tableAutoScroll.ts'
import Cookies from 'js-cookie'

import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import '@/assets/styles/index.scss' // global css

import zhLocale from 'element-plus/es/locale/lang/zh-cn'
import enLocale from 'element-plus/es/locale/lang/en'
import App from './App.vue'
import router from './router'
import store from './store'

// i18n js
import i18n from './lang/i18n.js'
import './permission' // permission control

// 注册指令
import plugins from './plugins' // plugins

// svg图标
import 'virtual:svg-icons-register'
import SvgIcon from '@/components/SvgIcon'
import elementIcons from '@/components/SvgIcon/svgicon'

import { useDict } from '@/utils/dict'
import { parseTime, resetForm, addDateRange, handleTree, selectDictLabel, selectDictLabels } from '@/utils/ruoyi'


// 字典标签组件
import DictTag from '@/components/DictTag'

import { getStoredLanguage, saveStoredLanguage } from "@/utils/languageStorage";
import VECharts from 'vue-echarts'
import { use } from 'echarts/core'
// 手动引入 ECharts 各模块来减小打包体积
//引入iconfont
import './assets/iconfont/iconfont.css'
import {
  CanvasRenderer
} from 'echarts/renderers'
import {
  PieChart,LineChart,BarChart,GaugeChart
} from 'echarts/charts'
import {
  TitleComponent,
  TooltipComponent,
  LegendComponent,
  GridComponent 
} from 'echarts/components'
use([
  CanvasRenderer,
  TitleComponent,
  TooltipComponent,
  LegendComponent,
  GridComponent,
  PieChart,
  LineChart,
  BarChart,
  GaugeChart
]);


// 设置语言
let locale = getStoredLanguage() === 'en-US' ? enLocale : zhLocale
const app = createApp(App)
// 全局方法挂载
app.config.globalProperties.useDict = useDict
app.config.globalProperties.parseTime = parseTime

// 此段代码写入main.js中
app.config.globalProperties.$t = i18n.global.t
app.config.globalProperties.$te = i18n.global.te

app.config.globalProperties.tLang = (parent, item) => {
  if (i18n.global.te(parent + "." + item)) {
    return i18n.global.t(parent + "." + item)
  }
  return item;
}

// 全局注册组件（也可以使用局部注册）
app.component('v-chart', VECharts)
app.component('DictTag', DictTag)


app.directive('tableAutoScroll', tableAutoScroll)

// app.use(createPinia())
app.use(router)
app.use(store)
app.use(i18n)
app.use(plugins)
app.use(elementIcons)
app.component('svg-icon', SvgIcon)
// 使用element-plus 并且设置全局的大小
app.use(ElementPlus, {
    locale: locale,
    // 支持 large、default、small
    size: Cookies.get('size') || 'default'
  })
app.mount('#app')
