import { createApp } from 'vue'

import Cookies from 'js-cookie'

import 'normalize.css/normalize.css'

import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import zhCn from 'element-plus/es/locale/lang/zh-cn'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import './styles/element-variables.scss'
import '@/styles/index.scss'

import App from './App.vue'
import store from './store'
import router from './router'

import SvgIcon from '@/components/SvgIcon/index.vue'
import './icons'
import './permission'
import './utils/error-log'

import * as filters from './filters'

const app = createApp(App)

app.use(ElementPlus, {
  locale: zhCn,
  size: Cookies.get('size') || 'default'
})

// 全局注册 Element Plus 图标组件
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component)
}

app.use(store)
app.use(router)

// 注册全局过滤器（Vue3 过滤器为普通函数，通过 globalProperties 提供）
app.component('svg-icon', SvgIcon)

app.config.globalProperties.$filters = filters

// 设置错误处理器
if (window.__setErrorhandler__) {
  window.__setErrorhandler__(app)
}

app.mount('#app')
