<template>
  <view class="launch-page">
    <!-- 背景图：与登录页一致的青山绿水 -->
    <image class="bg-img" src="/static/login-bg.jpeg" mode="aspectFill" />
    <!-- 柔光蒙版：与登录页一致的渐变 -->
    <view class="veil"></view>

    <!-- 内容层 -->
    <view class="content">
      <view class="brand">
        <view class="logo">
          <view class="leaf">
            <view class="leaf-vein"></view>
          </view>
        </view>
        <text class="title">绿水青山</text>
        <text class="subtitle">与自然同行</text>
      </view>

      <!-- 加载指示：嫩芽绿呼吸点 -->
      <view class="loading">
        <view class="dot" v-for="i in 3" :key="i"></view>
      </view>
    </view>
  </view>
</template>

<script setup lang="ts">
import { onLoad } from '@dcloudio/uni-app'
import { useAuthStore } from '@/stores'
import { delay } from '@/utils'

const authStore = useAuthStore()

onLoad(async () => {
  await delay(800)
  authStore.checkLogin()
  if (authStore.isLoggedIn && authStore.userRole) {
    uni.switchTab({ url: '/pages/home/home' })
  } else {
    uni.reLaunch({ url: '/pages/login/login' })
  }
})
</script>

<style scoped>
/* ==================== 页面外壳：与登录页一致 ==================== */
.launch-page {
  position: relative;
  max-width: 448px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background-color: #f6fbf9;     /* 云雾白兜底 */
}

.bg-img {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
}

.veil {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.52) 0%,
    rgba(246, 251, 249, 0.18) 38%,
    rgba(246, 251, 249, 0.10) 58%,
    rgba(31, 71, 56, 0.22) 100%
  );
}

/* ==================== 内容层 ==================== */
.content {
  position: relative;
  z-index: 2;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 56px 32px calc(40px + env(safe-area-inset-bottom));
}

.brand {
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* 磨砂玻璃 Logo 容器：与登录页一致 */
.logo {
  width: 76px;
  height: 76px;
  border-radius: 24px;
  background-color: rgba(255, 255, 255, 0.86);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 10px 28px -8px rgba(54, 143, 111, 0.45);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

/* 叶子 Logo（CSS 绘制，与登录页一致） */
.leaf {
  position: relative;
  width: 38px;
  height: 38px;
  background: linear-gradient(135deg, #a4d898 0%, #368f6f 100%);
  border-radius: 4px 28px 4px 28px;
  transform: rotate(45deg);
}

.leaf-vein {
  position: absolute;
  left: 50%;
  top: 4px;
  bottom: 4px;
  width: 2px;
  margin-left: -1px;
  border-radius: 2px;
  background-color: rgba(255, 255, 255, 0.7);
}

.title {
  margin-top: 22px;
  font-size: 34px;
  font-weight: 800;
  letter-spacing: 6px;
  color: #368f6f;                /* 青山绿 */
}

.subtitle {
  margin-top: 10px;
  font-size: 14px;
  letter-spacing: 4px;
  color: #709484;                /* 晨雾灰绿 */
}

/* ==================== 加载指示 ==================== */
.loading {
  display: flex;
  gap: 10px;
  margin-top: 48px;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: #a4d898;     /* 嫩芽绿 */
  animation: breathe 1.2s ease-in-out infinite;
}

.dot:nth-child(2) {
  animation-delay: 0.2s;
}

.dot:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes breathe {
  0%, 100% { opacity: 0.3; transform: scale(0.8); }
  50% { opacity: 1; transform: scale(1.2); }
}
</style>
