<script setup>
import { RouterView } from 'vue-router'
import { ref, onMounted } from 'vue'
import { isMobile } from './utils/mobileDetector.js'

const isLoading = ref(true)

onMounted(() => {
  // 只在移动端显示loading，PC端直接显示内容
  if (isMobile()) {
    // 移动端：延迟显示，避免PC样式闪现
    setTimeout(() => {
      isLoading.value = false
    }, 500)
  } else {
    // PC端：立即显示内容
    isLoading.value = false
  }
})
</script>

<template>
  <div class="app">
    <!-- Loading状态 -->
    <div v-if="isLoading" class="loading-container">
      <div class="loading-spinner">
        <div class="spinner"></div>
        <div class="loading-text">加载中...</div>
      </div>
    </div>
    
    <!-- 路由出口 -->
    <RouterView v-else />
  </div>
</template>

<style>
/* 引入阿里巴巴普惠体3字体 */
/* @import url('https://fonts.alicdn.com/t/c/font_4406263_pofp8o0bkt.css'); */

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: 'Alibaba PuHuiTi 3.0';
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

#app {
  height: 100%;
}

/* Loading样式 */
.loading-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: #EBF3FF;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}

.loading-spinner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid #e5e7eb;
  border-top: 3px solid #3e7bfa;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

.loading-text {
  font-size: 18px;
  color: #6b7280;
  font-weight: 500;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}
</style>