<template>
  <el-config-provider :locale="appStore.locale" :size="appStore.size">
    <router-view />
  </el-config-provider>
</template>

<script setup lang="ts">
import { useSettingsStore } from '@/store/modules/settings';
import { handleThemeStyle } from '@/utils/theme';
import { useAppStore } from '@/store/modules/app';
import { useUserStore } from '@/store/modules/user';

const appStore = useAppStore();
const userStore = useUserStore();

onMounted(() => {
  nextTick(() => {
    // 初始化主题样式
    handleThemeStyle(useSettingsStore().theme);
  });
});

// 监听租户名称变化，动态更新页面标题
watch(
  () => userStore.tenantName,
  (value) => {
    if (value) {
      document.title = userStore.tenantName;
    } else {
      document.title = import.meta.env.VITE_APP_TITLE;
    }
  },
  {
    immediate: true,
  }
);
</script>
