<template>
	<el-config-provider :locale="i18nLocale" v-if="isRouterAlive" :button="config" :size="assemblySize">
		<router-view></router-view>
	</el-config-provider>
</template>

<script setup lang="ts">
import { ref, reactive, computed, nextTick, provide } from "vue";
import { GlobalStore } from "@/stores";
import { useTheme } from "@/hooks/useTheme";
import { getBrowserLang } from "@/utils/util";
import { ElConfigProvider } from "element-plus";
import zhCn from "element-plus/es/locale/lang/zh-cn";
import en from "element-plus/es/locale/lang/en";

// 初始化主题配置
const { initTheme } = useTheme();
initTheme();

const isRouterAlive = ref(true);
const reload = () => {
	isRouterAlive.value = false;
	nextTick(() => {
		isRouterAlive.value = true;
	});
};

provide("reload", reload);

const globalStore = GlobalStore();
// 配置element按钮文字中间是否有空格
const config = reactive({
	autoInsertSpace: false
});

// element 语言配置
const i18nLocale = computed(() => {
	if (globalStore.language && globalStore.language == "zh") return zhCn;
	if (globalStore.language == "en") return en;
	return getBrowserLang() == "zh" ? zhCn : en;
});

// 配置全局组件大小
const assemblySize = computed(() => globalStore.assemblySize);
</script>
<style lang="scss">
// 地图的搜索层级功能 去掉或者加上scope就会导致地图搜索失效
.amap-sug-result {
	z-index: 2999 !important;
	.auto-item {
		padding-left: 8px;
		padding-right: 8px;
		font-size: 20px;
		color: #666;
	}
}
</style>
