<template>
  <div class="prize-statistics-page">
    <!-- 现代化页面头部 -->
    <div class="page-header-modern">
      <div class="header-content">
        <button class="back-btn" @click="goBack">
          <svg viewBox="0 0 24 24" class="back-icon">
            <path d="M15.41 7.41L14 6l-6 6 6 6 1.41-1.41L10.83 12z"></path>
          </svg>
        </button>
        <div class="header-info">
          <div class="header-text">
            <h1 class="header-title">奖金统计</h1>
            <p class="header-subtitle">查看您的中奖奖金统计数据</p>
          </div>
        </div>
        
        <!-- 彩票类型筛选 -->
        <div class="lottery-type-filter">
          <span class="filter-label">请选择彩票类型</span>
          <div class="select-wrapper">
            <el-select v-model="currentLotteryType" placeholder="选择彩票类型" @change="handleLotteryTypeChange" class="lottery-select">
              <el-option
                v-for="item in lotteryTypes"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </div>
        </div>
      </div>
    </div>

    <!-- 主要内容 -->
    <div class="statistics-content">
      <!-- 加载状态 -->
      <div v-if="loading" class="loading-container">
        <div class="loading-spinner">
          <div class="spinner"></div>
          <p class="loading-text">正在加载数据...</p>
        </div>
      </div>

      <!-- 数据展示 -->
      <div v-else class="data-container">
        <!-- 总奖金卡片 -->
        <div class="total-prize-card">
          <h2 class="total-prize-title">总奖金: <span class="total-prize-amount">¥{{ formatMoney(totalPrize) }}</span></h2>
        </div>

        <!-- 奖项明细表格 -->
        <div class="prize-table-container">
          <div class="table-header">
            <div class="header-cell award-type">奖项</div>
            <div class="header-cell win-count">中奖次数</div>
            <div class="header-cell prize-amount">累计奖金(元)</div>
          </div>
          
          <div v-if="prizeData.length === 0" class="no-data">
            <svg class="no-data-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
              <path d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"></path>
            </svg>
            <p class="no-data-text">No Data</p>
          </div>
          
          <div v-else class="table-body">
            <div v-for="(item, index) in prizeData" :key="index" class="table-row">
              <div class="table-cell award-type">{{ item.prizeLevel }}</div>
              <div class="table-cell win-count">{{ item.winningCount }}</div>
              <div class="table-cell prize-amount">{{ formatMoney(item.subtotal) }}</div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import api from '../../api/index.js'
import { userStore } from '../../store/user.js'
import { ElSelect, ElOption } from 'element-plus'

export default {
  name: 'PrizeStatistics',
  components: {
    ElSelect,
    ElOption
  },
  data() {
    return {
      loading: false,
      totalPrize: 0,
      prizeData: [],
      currentLotteryType: 'ssq',
      lotteryTypes: [
        { value: 'ssq', label: '双色球' },
        { value: 'dlt', label: '大乐透' }
        // { value: '3d', label: '福彩3D' },
        // { value: 'qlc', label: '七乐彩' },
        // { value: 'qxc', label: '七星彩' },
        // { value: 'pl3', label: '排列3' },
        // { value: 'pl5', label: '排列5' },
        // { value: 'kl8', label: '快乐8' }
      ]
    }
  },
  async mounted() {
    await this.loadPrizeStatistics()
  },
  methods: {
    async loadPrizeStatistics() {
      this.loading = true
      try {
        const userId = userStore.user?.id
        if (!userId) {
          this.$router.push('/login')
          return
        }

        const response = await api.get('/ball-analysis/prize-statistics', {
          params: {
            lotteryType: this.currentLotteryType
          }
        })
        
        if (response && response.success) {
          const data = response.data || {}
          this.totalPrize = data.totalPrize || 0
          this.prizeData = data.prizeDetails || []
        } else {
          this.$message.error('获取奖金统计数据失败')
        }
      } catch (error) {
        console.error('加载奖金统计数据失败:', error)
        this.$message.error('加载数据失败，请重试')
      } finally {
        this.loading = false
      }
    },
    
    handleLotteryTypeChange() {
      // 如果选择大乐透，跳转到大乐透奖金统计页面
      if (this.currentLotteryType === 'dlt') {
        this.$router.push('/daletou/prize-statistics')
        return
      }
      // 其他彩票类型暂时不支持，提示用户并重新加载数据
      if (this.currentLotteryType !== 'ssq') {
        this.$message.info('该彩票类型的奖金统计功能正在开发中')
        this.currentLotteryType = 'ssq'
        return
      }
      this.loadPrizeStatistics()
    },
    
    formatMoney(value) {
      if (typeof value !== 'number') return '0.00'
      return value.toFixed(2)
    },
    
    goBack() {
      // 直接跳转到我的页面
      this.$router.push('/profile')
    }
  }
}
</script>

<style scoped>
.prize-statistics-page {
  min-height: 100vh;
  background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
  padding: 0;
}

/* 页面头部 */
.page-header-modern {
  background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
  color: white;
  padding: 20px 0;
  position: relative;
  overflow: hidden;
}

.page-header-modern::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 800 200' preserveAspectRatio='none'%3E%3Cdefs%3E%3ClinearGradient id='grad1' x1='0%25' y1='0%25' x2='100%25' y2='0%25'%3E%3Cstop offset='0%25' style='stop-color:rgba(255,255,255,0.15);stop-opacity:1' /%3E%3Cstop offset='100%25' style='stop-color:rgba(255,255,255,0.05);stop-opacity:1' /%3E%3C/linearGradient%3E%3C/defs%3E%3C!-- Background waves --%3E%3Cpath d='M0,100 Q200,60 400,100 T800,100 L800,200 L0,200 Z' fill='rgba(255,255,255,0.08)'/%3E%3Cpath d='M0,120 Q200,80 400,120 T800,120 L800,200 L0,200 Z' fill='rgba(255,255,255,0.05)'/%3E%3C!-- Coins (金币) --%3E%3Ccircle cx='120' cy='85' r='28' stroke='rgba(255,255,255,0.35)' stroke-width='3' fill='rgba(255,255,255,0.15)'%3E%3Canimate attributeName='cy' values='85;75;85' dur='3s' repeatCount='indefinite'/%3E%3Canimate attributeName='r' values='28;32;28' dur='3s' repeatCount='indefinite'/%3E%3C/circle%3E%3Ctext x='120' y='95' font-size='24' fill='rgba(255,255,255,0.5)' font-weight='bold' text-anchor='middle'%3E%C2%A5%3Canimate attributeName='y' values='95;85;95' dur='3s' repeatCount='indefinite'/%3E%3C/text%3E%3Ccircle cx='200' cy='100' r='22' stroke='rgba(255,255,255,0.3)' stroke-width='2.5' fill='rgba(255,255,255,0.12)'%3E%3Canimate attributeName='cy' values='100;90;100' dur='3.5s' repeatCount='indefinite'/%3E%3C/circle%3E%3Ctext x='200' y='108' font-size='18' fill='rgba(255,255,255,0.45)' font-weight='bold' text-anchor='middle'%3E%C2%A5%3Canimate attributeName='y' values='108;98;108' dur='3.5s' repeatCount='indefinite'/%3E%3C/text%3E%3C!-- Trophy (奖杯) --%3E%3Cpath d='M280,75 L280,65 L330,65 L330,75 M270,75 L270,85 Q270,95 280,95 L280,110 L330,110 L330,95 Q340,95 340,85 L340,75 M275,110 L335,110 L335,115 L275,115 Z' stroke='rgba(255,255,255,0.4)' stroke-width='2.5' fill='none' stroke-linecap='round' stroke-linejoin='round'%3E%3Canimate attributeName='opacity' values='0.4;0.6;0.4' dur='3s' repeatCount='indefinite'/%3E%3C/path%3E%3Cpath d='M265,75 Q255,75 255,85' stroke='rgba(255,255,255,0.35)' stroke-width='2' fill='none'/%3E%3Cpath d='M345,75 Q355,75 355,85' stroke='rgba(255,255,255,0.35)' stroke-width='2' fill='none'/%3E%3C!-- Money bag (钱袋) --%3E%3Cellipse cx='420' cy='105' rx='20' ry='25' fill='rgba(255,255,255,0.2)' stroke='rgba(255,255,255,0.35)' stroke-width='2.5'%3E%3Canimate attributeName='ry' values='25;28;25' dur='2.8s' repeatCount='indefinite'/%3E%3C/ellipse%3E%3Cpath d='M410,80 Q415,75 420,77 Q425,75 430,80' stroke='rgba(255,255,255,0.35)' stroke-width='2.5' fill='none'/%3E%3Ctext x='420' y='110' font-size='16' fill='rgba(255,255,255,0.6)' font-weight='bold' text-anchor='middle'%3E%C2%A5%3C/text%3E%3C!-- Rising trend arrow (上升箭头) --%3E%3Cpolyline points='480,120 520,100 560,110 600,80 640,90' stroke='rgba(255,255,255,0.45)' stroke-width='3.5' fill='none' stroke-linecap='round' stroke-linejoin='round'%3E%3Canimate attributeName='points' values='480,120 520,100 560,110 600,80 640,90;480,115 520,95 560,105 600,75 640,85;480,120 520,100 560,110 600,80 640,90' dur='4s' repeatCount='indefinite'/%3E%3C/polyline%3E%3Cpolygon points='640,90 630,85 635,95' fill='rgba(255,255,255,0.45)'%3E%3Canimate attributeName='points' values='640,90 630,85 635,95;640,85 630,80 635,90;640,90 630,85 635,95' dur='4s' repeatCount='indefinite'/%3E%3C/polygon%3E%3C!-- Data points on trend --%3E%3Ccircle cx='480' cy='120' r='5' fill='rgba(255,255,255,0.7)'%3E%3Canimate attributeName='cy' values='120;115;120' dur='4s' repeatCount='indefinite'/%3E%3C/circle%3E%3Ccircle cx='520' cy='100' r='5' fill='rgba(255,255,255,0.7)'%3E%3Canimate attributeName='cy' values='100;95;100' dur='4s' repeatCount='indefinite'/%3E%3C/circle%3E%3Ccircle cx='560' cy='110' r='5' fill='rgba(255,255,255,0.7)'%3E%3Canimate attributeName='cy' values='110;105;110' dur='4s' repeatCount='indefinite'/%3E%3C/circle%3E%3Ccircle cx='600' cy='80' r='6' fill='rgba(255,255,255,0.8)'%3E%3Canimate attributeName='cy' values='80;75;80' dur='4s' repeatCount='indefinite'/%3E%3Canimate attributeName='r' values='6;8;6' dur='4s' repeatCount='indefinite'/%3E%3C/circle%3E%3Ccircle cx='640' cy='90' r='5' fill='rgba(255,255,255,0.7)'%3E%3Canimate attributeName='cy' values='90;85;90' dur='4s' repeatCount='indefinite'/%3E%3C/circle%3E%3C!-- Currency symbols --%3E%3Ctext x='700' y='100' font-size='36' fill='rgba(255,255,255,0.25)' font-weight='bold'%3E%C2%A5%3Canimate attributeName='y' values='100;85;100' dur='3.5s' repeatCount='indefinite'/%3E%3Canimate attributeName='opacity' values='0.25;0.4;0.25' dur='3.5s' repeatCount='indefinite'/%3E%3C/text%3E%3Ctext x='750' y='120' font-size='28' fill='rgba(255,255,255,0.2)' font-weight='bold'%3E%24%3Canimate attributeName='y' values='120;105;120' dur='3.2s' repeatCount='indefinite'/%3E%3Canimate attributeName='opacity' values='0.2;0.35;0.2' dur='3.2s' repeatCount='indefinite'/%3E%3C/text%3E%3C!-- Sparkle stars --%3E%3Ccircle cx='250' cy='130' r='2.5' fill='rgba(255,255,255,0.7)'%3E%3Canimate attributeName='opacity' values='0;1;0' dur='2.5s' repeatCount='indefinite'/%3E%3C/circle%3E%3Ccircle cx='380' cy='60' r='2' fill='rgba(255,255,255,0.6)'%3E%3Canimate attributeName='opacity' values='0;1;0' dur='2.8s' repeatCount='indefinite' begin='0.5s'/%3E%3C/circle%3E%3Ccircle cx='670' cy='130' r='2.5' fill='rgba(255,255,255,0.7)'%3E%3Canimate attributeName='opacity' values='0;1;0' dur='3s' repeatCount='indefinite' begin='1s'/%3E%3C/circle%3E%3Ccircle cx='450' cy='135' r='2' fill='rgba(255,255,255,0.6)'%3E%3Canimate attributeName='opacity' values='0;1;0' dur='2.6s' repeatCount='indefinite' begin='1.5s'/%3E%3C/circle%3E%3C!-- Additional decorative coins --%3E%3Ccircle cx='80' cy='120' r='15' stroke='rgba(255,255,255,0.25)' stroke-width='2' fill='rgba(255,255,255,0.1)'%3E%3Canimate attributeName='cy' values='120;110;120' dur='3.8s' repeatCount='indefinite'/%3E%3C/circle%3E%3Ctext x='80' y='127' font-size='12' fill='rgba(255,255,255,0.4)' font-weight='bold' text-anchor='middle'%3E%C2%A5%3Canimate attributeName='y' values='127;117;127' dur='3.8s' repeatCount='indefinite'/%3E%3C/text%3E%3Ctext x='50' y='95' font-size='22' fill='rgba(255,255,255,0.18)' font-weight='bold'%3E%E2%86%97%3C/text%3E%3C/svg%3E");
  background-size: cover;
  background-position: center;
  opacity: 1;
  z-index: 0;
}

.header-content {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  padding: 0 20px;
  position: relative;
  z-index: 1;
}

.back-btn {
  background: rgba(255, 255, 255, 0.2);
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 12px;
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.3s ease;
  backdrop-filter: blur(10px);
  color: white;
  margin-right: 16px;
}

.back-btn:hover {
  background: rgba(255, 255, 255, 0.3);
  transform: scale(1.05);
}

.back-icon {
  width: 24px;
  height: 24px;
  fill: currentColor;
}

.header-info {
  flex: 1;
}

.header-title {
  font-size: 24px;
  font-weight: 700;
  margin: 0 0 4px 0;
  color: white;
}

.header-subtitle {
  font-size: 14px;
  opacity: 0.8;
  margin: 0;
}

/* 主要内容 */
.statistics-content {
  max-width: 850px;
  margin: 0 auto;
  padding: 16px 16px;
}

/* 加载状态 */
.loading-container {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 300px;
}

.loading-spinner {
  text-align: center;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid #f3f3f3;
  border-top: 4px solid #4facfe;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin: 0 auto 16px;
}

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

.loading-text {
  color: #666;
  font-size: 14px;
  margin: 0;
}

/* 数据容器 */
.data-container {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 0 5px;
}

/* 总奖金卡片 */
.total-prize-card {
  background: #fff9f9;
  border-radius: 12px;
  padding: 24px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
  text-align: center;
  border: 1px solid #ffecec;
}

.total-prize-title {
  font-size: 20px;
  font-weight: 600;
  color: #333;
  margin: 0;
}

.total-prize-amount {
  color: #ff6b6b;
  font-size: 24px;
  font-weight: 700;
}

/* 奖项明细表格 */
.prize-table-container {
  background: white;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
  border: 1px solid #e9ecef;
}

.table-header {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  background: #f8f9fa;
  padding: 16px;
  font-weight: 600;
  color: #495057;
  border-bottom: 1px solid #e9ecef;
}

.header-cell {
  text-align: center;
  font-size: 16px;
}

.table-body {
  display: flex;
  flex-direction: column;
}

.table-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  padding: 16px;
  border-bottom: 1px solid #e9ecef;
  transition: background 0.3s ease;
}

.table-row:last-child {
  border-bottom: none;
}

.table-row:hover {
  background: #f8f9fa;
}

.table-cell {
  text-align: center;
  font-size: 15px;
  color: #495057;
}

.award-type {
  font-weight: 500;
}

.prize-amount {
  color: #ff6b6b;
  font-weight: 500;
}

/* 无数据状态 */
.no-data {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  color: #adb5bd;
}

.no-data-icon {
  width: 48px;
  height: 48px;
  stroke: currentColor;
  margin-bottom: 16px;
}

.no-data-text {
  font-size: 16px;
  margin: 0;
}

/* 彩票类型筛选 */
.lottery-type-filter {
  margin-left: 16px;
  display: flex;
  align-items: center;
}

.filter-label {
  color: white;
  font-size: 14px;
  margin-right: 10px;
  white-space: nowrap;
  font-weight: 500;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.select-wrapper {
  position: relative;
  border-radius: 20px;
  overflow: hidden;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.1);
}

.lottery-select {
  width: 140px;
}

/* 自定义Element UI下拉框样式 */
:deep(.el-select .el-input__wrapper) {
  background: rgba(255, 255, 255, 0.9);
  box-shadow: none;
  border-radius: 20px;
  padding: 0 15px;
  border: 2px solid rgba(255, 255, 255, 0.8);
  transition: all 0.3s ease;
}

:deep(.el-select .el-input__wrapper:hover) {
  background: white;
  transform: translateY(-1px);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
}

:deep(.el-select .el-input__inner) {
  color: #333;
  font-size: 14px;
  font-weight: 500;
  height: 36px;
}

:deep(.el-select .el-select__caret) {
  color: #4facfe;
  transition: transform 0.3s;
}

:deep(.el-select-dropdown__item.selected) {
  color: #4facfe;
  font-weight: bold;
  position: relative;
}

:deep(.el-select-dropdown__item.selected::after) {
  content: "";
  position: absolute;
  right: 15px;
  top: 50%;
  transform: translateY(-50%);
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background-color: #4facfe;
}

:deep(.el-select-dropdown__item:hover) {
  background-color: #f0f9ff;
}

:deep(.el-popper.is-light) {
  border-radius: 15px;
  border: none;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.12);
}

:deep(.el-select-dropdown__wrap) {
  max-height: 280px;
}

:deep(.el-select-dropdown__list) {
  padding: 8px 0;
}

:deep(.el-scrollbar__bar.is-horizontal) {
  display: none;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .page-header-modern {
    padding: 16px 0;
  }
  
  .header-content {
    padding: 0 16px;
    flex-wrap: wrap;
  }
  
  .lottery-type-filter {
    margin-left: 0;
    margin-top: 12px;
    width: 100%;
    justify-content: flex-start;
  }
  
  .filter-label {
    font-size: 13px;
    margin-right: 8px;
  }
  
  .lottery-select {
    width: 130px;
  }
  
  .back-btn {
    width: 40px;
    height: 40px;
    margin-right: 12px;
  }
  
  .back-icon {
    width: 20px;
    height: 20px;
  }
  
  .header-title {
    font-size: 20px;
  }
  
  .header-subtitle {
    font-size: 12px;
  }
  
  .statistics-content {
    padding: 16px;
  }
  
  .total-prize-title {
    font-size: 18px;
  }
  
  .total-prize-amount {
    font-size: 22px;
  }
  
  .table-header {
    padding: 12px;
  }
  
  .header-cell {
    font-size: 14px;
  }
  
  .table-row {
    padding: 12px;
  }
  
  .table-cell {
    font-size: 14px;
  }
}

@media (max-width: 480px) {
  .header-content {
    padding: 0 12px;
  }
  
  .statistics-content {
    padding: 10px;
  }
  
  .total-prize-card {
    padding: 16px;
  }
  
  .total-prize-title {
    font-size: 16px;
  }
  
  .total-prize-amount {
    font-size: 20px;
  }
  
  .table-header {
    padding: 10px 8px;
  }
  
  .header-cell {
    font-size: 13px;
  }
  
  .table-row {
    padding: 10px 8px;
  }
  
  .table-cell {
    font-size: 13px;
  }
  
  .no-data-icon {
    width: 40px;
    height: 40px;
  }
  
  .no-data-text {
    font-size: 14px;
  }
}
</style>