<script setup lang="ts">
import { computed } from 'vue'
import { useI18n } from 'vue-i18n'
import { storeToRefs } from 'pinia'
import { useAuthStore } from '@/stores/auth'
import { AUTH_ENABLED } from '@/utils/featureFlags'
import aboutMountain from '@/assets/home/about-mountain.png'
import visionBlackhole from '@/assets/home/vision-blackhole.png'
import iconAsset from '@/assets/home/icon-asset.png'
import iconSpeed from '@/assets/home/icon-speed.png'
import iconGlobal from '@/assets/home/icon-global.png'
import iconFee from '@/assets/home/icon-fee.png'
import iconEco from '@/assets/home/icon-eco.png'
import iconMission from '@/assets/home/icon-mission.png'
import iconPurpose from '@/assets/home/icon-purpose.png'
import cardGlow1 from '@/assets/home/card-glow-1.png'
import cardGlow2 from '@/assets/home/card-glow-2.png'
import cardGlow3 from '@/assets/home/card-glow-3.png'
import cardGlow4 from '@/assets/home/card-glow-4.png'
import authVisual from '@/assets/auth/auth-visual.png'

const { t } = useI18n()

const advantages = computed(() => [
  { icon: iconAsset, glow: cardGlow1, titleKey: 'home.assetSafetyTitle', descKey: 'home.assetSafetyDesc' },
  { icon: iconSpeed, glow: cardGlow2, titleKey: 'home.highPerfTitle',    descKey: 'home.highPerfDesc' },
  { icon: iconGlobal, glow: cardGlow3, titleKey: 'home.globalComplianceTitle', descKey: 'home.globalComplianceDesc' },
  { icon: iconFee,   glow: cardGlow4, titleKey: 'home.transparentFeeTitle', descKey: 'home.transparentFeeDesc' },
])

const visionItems = computed(() => [
  { icon: iconEco,     titleKey: 'home.ecoTitle',     descKey: 'home.ecoDesc' },
  { icon: iconMission, titleKey: 'home.missionTitle', descKey: 'home.missionDesc' },
  { icon: iconPurpose, titleKey: 'home.purposeTitle', descKey: 'home.purposeDesc' },
])

const { isLoggedIn } = storeToRefs(useAuthStore())
</script>

<template>
  <main class="page-main home">
    <!-- Hero -->
    <section class="hero">
      <div class="page-container hero-inner">
        <div class="hero-text">
          <h1 class="hero-title">{{ t('home.heroTitle') }}</h1>
          <p class="hero-desc">{{ t('home.heroDesc') }}</p>
          <div class="hero-actions">
            <RouterLink v-if="AUTH_ENABLED && !isLoggedIn" to="/register" class="btn btn-primary">{{ t('home.register') }}</RouterLink>
            <RouterLink
              to="/market"
              class="btn"
              :class="AUTH_ENABLED && !isLoggedIn ? 'btn-outline' : 'btn-primary'"
            >{{ t('home.viewMarket') }}</RouterLink>
            <RouterLink v-if="!AUTH_ENABLED" to="/download" class="btn btn-outline">{{ t('home.downloadApp') }}</RouterLink>
          </div>
        </div>
        <div class="hero-visual">
          <img
            :src="authVisual"
            :alt="t('home.heroImageAlt')"
            class="hero-visual-img"
            loading="eager"
            decoding="async"
          >
        </div>
      </div>
    </section>

    <!-- 平台核心优势 -->
    <section class="section advantages-section">
      <div class="page-container">
        <h2 class="section-title">{{ t('home.coreAdvantages') }}</h2>
        <div class="advantages-grid">
          <div
            v-for="item in advantages"
            :key="item.titleKey"
            class="advantage-card"
            :style="{ backgroundImage: `url(${item.glow})` }"
          >
            <img :src="item.icon" :alt="t(item.titleKey)" class="advantage-icon" />
            <h3 class="advantage-title">{{ t(item.titleKey) }}</h3>
            <p class="advantage-desc">{{ t(item.descKey) }}</p>
          </div>
          <div class="advantages-cross" aria-hidden="true" />
        </div>
      </div>
    </section>

    <!-- 关于我们 -->
    <section class="about-section">
      <div class="page-container about-inner">
        <div class="about-visual">
          <img :src="aboutMountain" :alt="t('home.aboutImageAlt')" class="about-image" />
        </div>
        <div class="about-content">
          <h2 class="about-title">{{ t('home.aboutUs') }}</h2>
          <p class="about-desc">{{ t('home.aboutDesc') }}</p>
          <p class="about-meta">{{ t('home.foundedYear') }}</p>
          <p class="about-meta">{{ t('home.headquarters') }}</p>
        </div>
      </div>
    </section>

    <!-- 我们的愿景 -->
    <section class="vision-section">
      <div class="page-container">
        <h2 class="section-title">{{ t('home.ourVision') }}</h2>
        <p class="vision-subtitle">{{ t('home.visionSubtitle') }}</p>
        <div
          class="vision-deco"
          :style="{ backgroundImage: `url(${visionBlackhole})` }"
        />
        <div class="vision-grid">
          <div v-for="item in visionItems" :key="item.titleKey" class="vision-card">
            <img :src="item.icon" :alt="t(item.titleKey)" class="vision-icon" />
            <h3 class="vision-title">{{ t(item.titleKey) }}</h3>
            <p class="vision-desc">{{ t(item.descKey) }}</p>
          </div>
        </div>
      </div>
    </section>
  </main>
</template>

<style scoped>
.home {
  background: #0a0a0a;
  color: #fff;
}

/* ==========================================================================
   Hero
   ========================================================================== */
.hero {
  position: relative;
  overflow: hidden;
  background:
    radial-gradient(ellipse 65% 45% at 50% 28%, rgba(240, 185, 11, 0.12) 0%, transparent 60%),
    #0a0a0a;
}

.hero-inner {
  padding-top: var(--space-20);
  padding-bottom: var(--space-20);
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr);
  gap: var(--space-10);
  align-items: center;
}

.hero-visual {
  display: flex;
  justify-content: center;
  align-items: center;
}

.hero-visual-img {
  width: 100%;
  max-width: 560px;
  height: auto;
  display: block;
  object-fit: contain;
  user-select: none;
  pointer-events: none;
}

.hero-title {
  font-size: 48px;
  font-weight: 700;
  line-height: 1.3;
  color: #fff;
  margin-bottom: var(--space-6);
  letter-spacing: 0.5px;
  white-space: pre-line;
}

.hero-desc {
  font-size: 15px;
  color: #999;
  line-height: 1.85;
  max-width: 480px;
  margin-bottom: var(--space-8);
}

.hero-actions {
  display: flex;
  gap: var(--space-4);
  flex-wrap: wrap;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 132px;
  height: 44px;
  padding: 0 var(--space-6);
  font-size: 15px;
  font-weight: 600;
  border-radius: 22px;
  text-decoration: none;
  transition: all 0.2s ease;
}
.btn-primary {
  background: var(--color-primary);
  color: #1a1a1a;
}
.btn-primary:hover {
  background: var(--color-primary-hover);
  transform: translateY(-1px);
}
.btn-outline {
  background: transparent;
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.3);
}
.btn-outline:hover {
  border-color: var(--color-primary);
  color: var(--color-primary);
}

/* ==========================================================================
   平台核心优势
   ========================================================================== */
.advantages-section {
  background: #0a0a0a;
  padding: var(--space-20) 0;
  position: relative;
}

.section-title {
  font-size: 32px;
  font-weight: 700;
  color: #fff;
  text-align: center;
  margin-bottom: var(--space-12);
}

.advantages-grid {
  position: relative;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-5);
  max-width: 920px;
  margin: 0 auto;
}

.advantage-card {
  position: relative;
  padding: var(--space-8) var(--space-6);
  background-color: #111;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 14px;
  overflow: hidden;
  transition: transform 0.25s ease, border-color 0.25s ease;
}
.advantage-card:hover {
  transform: translateY(-2px);
  border-color: rgba(240, 185, 11, 0.3);
}

.advantage-icon {
  width: 56px;
  height: 56px;
  object-fit: contain;
  margin-bottom: var(--space-4);
}

.advantage-title {
  font-size: 20px;
  font-weight: 600;
  color: var(--color-primary);
  margin-bottom: var(--space-3);
}

.advantage-desc {
  font-size: 13px;
  color: #999;
  line-height: 1.75;
}

.advantages-cross {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at 50% 50%, rgba(240, 185, 11, 0.35) 0%, transparent 12%),
    linear-gradient(to right, transparent calc(50% - 0.5px), rgba(240, 185, 11, 0.25) calc(50% - 0.5px), rgba(240, 185, 11, 0.25) calc(50% + 0.5px), transparent calc(50% + 0.5px)),
    linear-gradient(to bottom, transparent calc(50% - 0.5px), rgba(240, 185, 11, 0.25) calc(50% - 0.5px), rgba(240, 185, 11, 0.25) calc(50% + 0.5px), transparent calc(50% + 0.5px));
}

/* ==========================================================================
   关于我们
   ========================================================================== */
.about-section {
  padding: var(--space-20) 0;
  background: #0a0a0a;
}

.about-inner {
  display: grid;
  grid-template-columns: 1.1fr 1fr;
  gap: var(--space-12);
  align-items: center;
}

.about-visual {
  display: flex;
  justify-content: center;
}

.about-image {
  width: 100%;
  max-width: 460px;
  height: auto;
  display: block;
}

.about-title {
  font-size: 32px;
  font-weight: 700;
  color: #fff;
  margin-bottom: var(--space-5);
}

.about-desc {
  font-size: 14px;
  color: #999;
  line-height: 1.85;
  margin-bottom: var(--space-5);
  max-width: 440px;
}

.about-meta {
  font-size: 15px;
  font-weight: 600;
  color: var(--color-primary);
  margin-bottom: var(--space-2);
}

/* ==========================================================================
   我们的愿景
   ========================================================================== */
.vision-section {
  background: #0a0a0a;
  padding: var(--space-20) 0 var(--space-16);
  position: relative;
  overflow: hidden;
}

.vision-subtitle {
  text-align: center;
  font-size: 16px;
  color: var(--color-primary);
  font-weight: 500;
  margin-top: calc(-1 * var(--space-8));
  margin-bottom: var(--space-8);
}

.vision-deco {
  width: 100%;
  max-width: 680px;
  height: 180px;
  margin: 0 auto var(--space-10);
  background-size: contain;
  background-position: center;
  background-repeat: no-repeat;
}

.vision-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-5);
  max-width: 920px;
  margin: 0 auto;
}

.vision-card {
  position: relative;
  padding: var(--space-8) var(--space-6);
  background: linear-gradient(180deg, #1a1a1a 0%, #0e0e0e 100%);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 14px;
  transition: transform 0.25s ease, border-color 0.25s ease;
}
.vision-card:hover {
  transform: translateY(-2px);
  border-color: rgba(240, 185, 11, 0.3);
}

.vision-icon {
  width: 56px;
  height: 56px;
  object-fit: contain;
  margin-bottom: var(--space-4);
}

.vision-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--color-primary);
  margin-bottom: var(--space-2);
}

.vision-desc {
  font-size: 13px;
  color: #999;
  line-height: 1.7;
}

/* ==========================================================================
   响应式 · 平板
   ========================================================================== */
@media (max-width: 960px) {
  .hero-inner {
    padding-top: var(--space-12);
    padding-bottom: var(--space-12);
    grid-template-columns: 1fr;
    text-align: center;
    gap: var(--space-8);
  }
  .hero-title { font-size: 36px; }
  .hero-desc { margin-left: auto; margin-right: auto; }
  .hero-actions { justify-content: center; }
  .hero-visual-img { max-width: 420px; margin: 0 auto; }

  .about-inner {
    grid-template-columns: 1fr;
    gap: var(--space-8);
    text-align: center;
  }
  .about-desc { margin-left: auto; margin-right: auto; }
  .about-image { max-width: 360px; }

  .vision-grid { grid-template-columns: repeat(3, 1fr); gap: var(--space-4); }
}

/* ==========================================================================
   响应式 · 手机
   ========================================================================== */
@media (max-width: 640px) {
  .hero {
    background:
      radial-gradient(ellipse 80% 40% at 50% 25%, rgba(240, 185, 11, 0.15) 0%, transparent 65%),
      #0a0a0a;
  }
  .hero-inner {
    padding-top: var(--space-10);
    padding-bottom: var(--space-10);
    gap: var(--space-6);
  }
  .hero-title { font-size: 26px; line-height: 1.35; }
  .hero-desc { font-size: 13px; line-height: 1.8; }
  .btn { min-width: 120px; height: 40px; font-size: 14px; }
  .hero-visual-img { max-width: min(100%, 320px); }

  .section-title { font-size: 24px; margin-bottom: var(--space-8); }

  .advantages-section { padding: var(--space-12) 0; }
  .advantages-grid { gap: var(--space-3); }
  .advantage-card { padding: var(--space-6) var(--space-4); }
  .advantage-icon { width: 44px; height: 44px; margin-bottom: var(--space-3); }
  .advantage-title { font-size: 16px; margin-bottom: var(--space-2); }
  .advantage-desc { font-size: 12px; line-height: 1.7; }

  .about-section { padding: var(--space-12) 0; }
  .about-title { font-size: 24px; }
  .about-desc { font-size: 13px; }
  .about-meta { font-size: 14px; }
  .about-image { max-width: 280px; }

  .vision-section { padding: var(--space-12) 0; }
  .vision-subtitle { font-size: 13px; padding: 0 var(--space-4); margin-top: calc(-1 * var(--space-6)); }
  .vision-deco { height: 120px; }
  .vision-grid { grid-template-columns: 1fr; gap: var(--space-3); }
  .vision-card { padding: var(--space-6) var(--space-5); }
  .vision-icon { width: 48px; height: 48px; }
  .vision-title { font-size: 16px; }
  .vision-desc { font-size: 12px; }
}
</style>
