import { createApp } from 'vue';
import { createPinia } from 'pinia';
import * as ElementPlusIconsVue from '@element-plus/icons-vue';
import App from './App.vue';
import router from './router';
import { usePermissStore } from './store/permiss';
import ElementPlus from 'element-plus';
import es from 'element-plus/es/locale/lang/es';
import en from 'element-plus/es/locale/lang/en';
import 'element-plus/dist/index.css';
import './assets/css/icon.css';
import i18n from '@/utils/i18n'
const app = createApp(App);
app.use(createPinia());
app.use(router);

// 注册elementplus图标
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component);
}
// 自定义权限指令
const permiss = usePermissStore();
app.directive('permiss', {
    mounted(el, binding) {
        if (binding.value && !permiss.userAuth.includes(String(binding.value))) {
            el['hidden'] = true;
        }
    },
});
if (navigator.language.startsWith('es')) {
  app.use(ElementPlus, { locale: es })
}else{
  app.use(ElementPlus, { locale: en })
}
app.config.globalProperties.$router = router
app.use(i18n)
app.mount('#app');
