<template>
  <div>
    <el-config-provider :locale="elementPlusLocale">
      <NuxtLayout>
        <NuxtPage />
      </NuxtLayout>
    </el-config-provider>
  </div>
</template>

<script setup lang="ts">
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 { login } = useStrapiAuth();

const { locale } = useI18n();

const elementPlusLocales = {
  'zh': zhCn,
  'en': en,
}

const elementPlusLocale = computed(() => elementPlusLocales[locale.value] || zhCn);

onMounted(() => {
  // 检查用户是否已登录
  const user = useStrapiUser();
  if (!user.value) {
    // 如果未登录，重定向到登录页面
    login({ identifier: 'remilia', password: 'huanshuo51' })
      .then(() => {
        console.log('Login successful');
      })
      .catch((error) => {
        console.error('Login failed:', error);
      });
  } else {
    console.log('User is already logged in:', user.value);
  }
});
</script>