<template>
  <footer class="footer">
    <!-- VIP区域 -->
    <div class="vip-section">
      <div class="vip-container">
        <div class="vip-left">
          <!-- VIP Logo预留位置 -->
          <div class="vip-logo">
            <img 
              v-if="vipLogoUrl" 
              :src="vipLogoUrl" 
              alt="VIP" 
              class="vip-logo-image"
            />
            <div v-else class="vip-logo-placeholder">
              <span class="vip-text">VIP</span>
            </div>
          </div>
          <div class="vip-text-content">
            <p class="vip-slogan">每一个决定都是未来的基石！现在就开始武装自己吧！</p>
          </div>
        </div>
        <div class="vip-right">
          <button class="recharge-button" @click="handleRecharge">
            为自己充值
          </button>
        </div>
      </div>
    </div>

    <!-- 底部信息区域 -->
    <div class="footer-main">
      <div class="footer-container">
        <!-- 左侧信息 -->
        <div class="footer-left">
          <!-- 主Logo预留位置 -->
          <div class="main-logo">
            <img 
              v-if="mainLogoUrl" 
              :src="mainLogoUrl" 
              alt="1818.Ai" 
              class="main-logo-image"
            />
            <div v-else class="main-logo-placeholder">
              <span class="logo-text">1818.Ai</span>
              <span class="studio-text">&lt;/&gt;studio</span>
            </div>
          </div>
          
          <div class="footer-content">
            <div class="copyright">
              <p>© STAROCEANWISDOM, powered by 1818ai.com</p>
            </div>
            
            <div class="description">
              <p>星洋智慧倾力打造的智能体工作流学习平台。在这里你可以上传下载工作流，学习智能体开发课程，在线调用 AIGC 应用，让 AI 高效应用更简单。</p>
            </div>
            
            <div class="legal-info">
              <div class="icp-info">
                <p class="icp"> <a href="https://beian.miit.gov.cn/#/Integrated/index" style="color: #ccc;">浙ICP备2025158455号-4        
                  1818ai.com</a></p>
                <div class="security-info">
                  <img 
                    v-if="emblemUrl" 
                    :src="emblemUrl" 
                    alt="国徽" 
                    class="emblem-image"
                  />
                  <div v-else class="emblem-placeholder"></div>
                  <p class="security-number"><a href="https://beian.mps.gov.cn/#/query/webSearch?code=33019202002704" style="color: #ccc;" rel="noreferrer" target="_blank">浙公网安备33019202002704号</a></p>
                </div>
              </div>
            </div>
          </div>
        </div>

        <!-- 右侧区域：主页显示社交媒体图标，其他页面显示企业微信二维码 -->
        <div class="footer-right">
          <!-- 主页：显示社交媒体图标 -->
          <div v-if="isHomePage" class="social-icons">
            <!-- bilibili Logo预留位置 -->
            <div class="bilibili-icon">
              <img 
                v-if="bilibiliLogoUrl" 
                :src="bilibiliLogoUrl" 
                alt="bilibili" 
                class="bilibili-icon-image"
              />
              <div v-else class="bilibili-icon-placeholder">
                <span class="icon-text"></span>
              </div>
            </div>
            
            <!-- 微信图标预留位置 -->
            <div class="wechat-icon">
              <img 
                v-if="wechatIconUrl" 
                :src="wechatIconUrl" 
                alt="微信" 
                class="wechat-icon-image"
              />
              <div v-else class="wechat-icon-placeholder">
                <span class="icon-text"></span>
              </div>
            </div>
            
            <!-- 小红书图标预留位置 -->
            <div class="xiaohongshu-icon">
              <img 
                v-if="xiaohongshuIconUrl" 
                :src="xiaohongshuIconUrl" 
                alt="小红书" 
                class="xiaohongshu-icon-image"
              />
              <div v-else class="xiaohongshu-icon-placeholder">
                <span class="icon-text"></span>
              </div>
            </div>
            
            <!-- 邮箱图标预留位置 -->
            <div class="email-icon">
              <img 
                v-if="emailIconUrl" 
                :src="emailIconUrl" 
                alt="邮箱" 
                class="email-icon-image"
              />
              <div v-else class="email-icon-placeholder">
                <span class="icon-text"></span>
              </div>
            </div>
          </div>

          <!-- 其他页面：显示企业微信二维码 -->
          <div v-else class="wechat-qr-section">
            <div v-if="loading" class="loading-text">加载中...</div>
            <div v-else-if="wechatQRCodes.length > 0" class="qr-codes">
              <div 
                v-for="qrCode in wechatQRCodes" 
                :key="qrCode.id" 
                class="qr-code-item"
              >
                <div class="qr-image-container">
                  <img 
                    :src="qrCode.qrCodeUrl" 
                    :alt="qrCode.description"
                    class="qr-code-image"
                  />
                </div>
                <p class="qr-description">{{ qrCode.description }}</p>
              </div>
            </div>
            <div v-else class="no-qr-codes">暂无企业微信二维码</div>
          </div>
        </div>
      </div>
    </div>
  </footer>
</template>

<script setup>
import { ref, computed, onMounted } from 'vue'
import vipLogo from '../assets/Footer_svg/VIP.svg'
import mainLogo from '../assets/Footer_svg/Footer_logo.svg'
import emblemIcon from '../assets/Footer_svg/emblemUrl.svg'
import bilibiliIcon from '../assets/Footer_svg/b.svg'
import wechatIcon from '../assets/Footer_svg/v.svg'
import xiaohongshuIcon from '../assets/Footer_svg/x.svg'
import emailIcon from '../assets/Footer_svg/e.svg'
import { useRouter, useRoute } from 'vue-router'
import { getWechatQRList } from '../api/user'

// 预留图片地址位
const vipLogoUrl = ref(vipLogo) // VIP Logo地址
const mainLogoUrl = ref(mainLogo) // 主Logo地址
const emblemUrl = ref(emblemIcon) // 国徽图标地址
const bilibiliLogoUrl = ref(bilibiliIcon) // bilibili Logo地址
const wechatIconUrl = ref(wechatIcon) // 微信图标地址
const xiaohongshuIconUrl = ref(xiaohongshuIcon) // 小红书图标地址
const emailIconUrl = ref(emailIcon) // 邮箱图标地址

// 企业微信二维码数据
const wechatQRCodes = ref([])
const loading = ref(false)

// 使用Vue 3 Composition API的useRouter和useRoute钩子
const router = useRouter()
const route = useRoute()

// 判断是否在主页
const isHomePage = computed(() => {
  return route.name === 'Home'
})

// 获取企业微信二维码
const fetchWechatQRCodes = async () => {
  if (isHomePage.value) return // 主页不需要获取二维码
  
  try {
    loading.value = true
    const response = await getWechatQRList()
    if (response && response.code === 200 && response.data) {
      wechatQRCodes.value = response.data.qrCodes || []
    }
  } catch (error) {
    console.error('获取企业微信二维码失败:', error)
    wechatQRCodes.value = []
  } finally {
    loading.value = false
  }
}

// 监听路由变化
onMounted(() => {
  fetchWechatQRCodes()
})

// 当路由变化时重新获取数据
const updateQRCodes = () => {
  fetchWechatQRCodes()
}

// 监听路由变化
router.afterEach(() => {
  updateQRCodes()
})

const handleRecharge = () => {
  router.push('/membership') // 跳转到充值套餐页面
}
</script>

<style scoped>
.footer {
  width: 100vw;
  background: #fff;
  margin-left: calc(50% - 50vw);
  margin-right: calc(50% - 50vw);
  box-sizing: border-box;

}

/* VIP区域样式 */
.vip-section {
  width: 100vw;
  height: 80px;
  background: linear-gradient(to bottom, rgba(247, 218, 191, 1), rgba(240, 187, 141, 1));
  display: flex;
  align-items: center;
}

.vip-container {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 40px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.vip-left {
  display: flex;
  align-items: center;
  gap: 20px;
}

.vip-logo {
  width: 90px;
  height: 45px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.vip-logo-image {
  width: auto;
  height: auto;
  max-width: 90px;
  max-height: 45px;
  object-fit: contain;
}

.vip-logo-placeholder {
  background: #fff;
  border-radius: 8px;
  padding: 8px 16px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.vip-text {
  font-family: Arial, sans-serif;
  font-weight: bold;
  font-size: 18px;
  color: #333;
}

.vip-slogan {
  font-family: Arial, sans-serif;
  font-size: 16px;
  color: #333;
  margin: 0;
  font-weight: 500;
}

.recharge-button {
  background: rgba(0, 0, 0, 1);
  color: rgba(255, 255, 255, 1);
  border: none;
  width: 146px;
  height: 48px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  background-color: rgba(51, 51, 51, 1);
  transition: background-color 0.3s ease;
}

.recharge-button:hover {
  background: #333;
}

/* 底部主区域样式 */
.footer-main {
  width: 100vw;
  background: #000;
  color: #fff;
  padding: 60px 0 40px;
  margin-left: calc(50% - 50vw);
  margin-right: calc(50% - 50vw);
  box-sizing: border-box;
}

.footer-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 40px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.footer-left {
  flex: 1;
  max-width: 600px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 20px;
}

.main-logo {
  margin-bottom: 0;
}

.main-logo-image {
  width: auto;
  height: auto;
  max-height: 60px;
  object-fit: contain;
}

.main-logo-placeholder {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.footer-content {
  width: 100%;
}

.logo-text {
  font-family: Arial, sans-serif;
  font-size: 32px;
  font-weight: bold;
  color: #fff;
}

.studio-text {
  font-family: Arial, sans-serif;
  font-size: 16px;
  color: #fff;
  opacity: 0.8;
}

.copyright {
  margin-bottom: 20px;
}

.copyright p {
  font-family: Arial, sans-serif;
  font-weight: 400;
  font-size: 14px;
  line-height: 20px;
  letter-spacing: 0px;
  color: #ccc;
  margin: 0;
  text-align: left;
}

.description {
  margin-bottom: 30px;
}

.description p {
  font-family: Arial, sans-serif;
  font-weight: 400;
  font-size: 14px;
  line-height: 20px;
  letter-spacing: 0px;
  color: #ccc;
  margin: 0;
  text-align: left;
}

.legal-info {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.icp-info {
  display: flex;
  align-items: center;
  gap: 20px;
}

.icp {
  font-family: Arial, sans-serif;
  font-weight: 400;
  font-size: 14px;
  line-height: 20px;
  letter-spacing: 0px;
  color: #999;
  margin: 0;
  text-align: left;
}

.security-info {
  display: flex;
  align-items: center;
  gap: 8px;
}

.national-emblem {
  width: 23px;
  height: 25px;
}

.emblem-image {
  width: auto;
  height: auto;
  max-width: 23px;
  max-height: 25px;
  object-fit: contain;
}

.emblem-placeholder {
  width: 23px;
  height: 25px;
  background: #ff0000;
  border-radius: 50%;
}

.security-number {
  font-family: Arial, sans-serif;
  font-weight: 400;
  font-size: 14px;
  line-height: 20px;
  letter-spacing: 0px;
  color: #999;
  margin: 0;
  text-align: left;
}

/* 右侧社交媒体 */
.footer-right {
  display: flex;
  align-items: flex-start;
  margin-top: 40px;
}

.social-icons {
  display: flex;
  gap: 15px;
  align-items: center;
}

.social-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.3s ease;
  padding: 8px;
  border-radius: 50%;
  background: #333;
}

.social-icon:hover {
  background: #555;
}

.social-icon-image {
  width: auto;
  height: auto;
  max-width: 24px;
  max-height: 24px;
  object-fit: contain;
}

.bilibili-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.3s ease;
}

.bilibili-icon-image {
  width: 53.99px;
  height: 24.05px;
  object-fit: contain;
}

.bilibili-icon-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
}

.wechat-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.3s ease;
}

.wechat-icon-image {
  width: 34.43px;
  height: 34px;
  object-fit: contain;
}

.wechat-icon-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
}

.xiaohongshu-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.3s ease;
}

.xiaohongshu-icon-image {
  width: 34.43px;
  height: 34px;
  object-fit: contain;
}

.xiaohongshu-icon-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
}

.email-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.3s ease;
}

.email-icon-image {
  width: 34.43px;
  height: 34px;
  object-fit: contain;
}

.email-icon-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-text {
  font-size: 18px;
  color: #fff;
}

/* 企业微信二维码区域样式 */
.wechat-qr-section {
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
  margin-top: 40px;
  width: fit-content;
  max-width: 100%;
}

.loading-text {
  font-family: Arial, sans-serif;
  font-size: 14px;
  color: #ccc;
  text-align: center;
  padding: 20px;
}

.qr-codes {
  display: flex;
  flex-direction: column;
  gap: 15px;
  max-width: 280px;
  width: fit-content;
}

.qr-code-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 0;
  margin: 0;
}

.qr-image-container {
  width: 120px;
  height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 10px;
  background: #fff;
  border-radius: 8px;
  padding: 8px;
}

.qr-code-image {
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: 4px;
}

.qr-description {
  font-family: Arial, sans-serif;
  font-size: 12px;
  line-height: 16px;
  color: #ccc;
  margin: 0;
  max-width: 200px;
  word-wrap: break-word;
}

.no-qr-codes {
  font-family: Arial, sans-serif;
  font-size: 14px;
  color: #999;
  text-align: center;
  padding: 20px;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .footer {
    width: 100vw;
    margin-left: calc(50% - 50vw);
    margin-right: calc(50% - 50vw);
  }
  
  .vip-section {
    height: auto;
    min-height: 80px;
    padding: 20px 0;
    width: 100vw;
    margin-left: calc(50% - 50vw);
    margin-right: calc(50% - 50vw);
  }
  
  .footer-main {
    width: 100vw;
    margin-left: calc(50% - 50vw);
    margin-right: calc(50% - 50vw);
  }
  
  .vip-container {
    flex-direction: column;
    gap: 20px;
    text-align: center;
    padding: 0 20px;
  }
  
  .vip-left {
    flex-direction: column;
    gap: 15px;
  }
  
  .footer-container {
    flex-direction: column;
    gap: 40px;
    padding: 0 20px;
  }
  
  .footer-right {
    align-items: center;
  }
  
  .social-icons {
    justify-content: center;
  }

  .wechat-qr-section {
    margin-top: 20px;
    align-items: center;
    justify-content: center;
  }

  .qr-codes {
    max-width: 100%;
  }

  .qr-code-item {
    padding: 0;
    margin: 0;
  }

  .qr-image-container {
    width: 100px;
    height: 100px;
  }

  .qr-description {
    font-size: 11px;
    max-width: 150px;
  }
}

@media (max-width: 480px) {
  .footer {
    width: 100vw;
    margin-left: calc(50% - 50vw);
    margin-right: calc(50% - 50vw);
  }
  
  .vip-section {
    height: auto;
    min-height: 80px;
    padding: 15px 0;
    width: 100vw;
    margin-left: calc(50% - 50vw);
    margin-right: calc(50% - 50vw);
  }
  
  .footer-main {
    width: 100vw;
    margin-left: calc(50% - 50vw);
    margin-right: calc(50% - 50vw);
    padding: 40px 0 30px;
  }
  
  .vip-container {
    padding: 0 15px;
  }
  
  .footer-container {
    padding: 0 15px;
  }
  
  .logo-text {
    font-size: 28px;
  }
  
  .vip-slogan {
    font-size: 14px;
  }
  
  .description p {
    font-size: 13px;
  }

  .wechat-qr-section {
    margin-top: 15px;
  }

  .qr-codes {
    gap: 15px;
  }

  .qr-code-item {
    padding: 0;
    margin: 0;
  }

  .qr-image-container {
    width: 80px;
    height: 80px;
    padding: 6px;
  }

  .qr-description {
    font-size: 10px;
    line-height: 14px;
    max-width: 120px;
  }
}
</style> 