<template>
  <div class="data-analysis-container">
    <!-- 页面头部 -->
    <el-page-header @back="goBack" class="page-header">
      <template #title>
        返回
      </template>
      <template #content>
        <div class="header-content">
          <el-icon :size="24" style="margin-right: 8px;"><DataAnalysisIcon /></el-icon>
          <span class="header-title">数据分析中心</span>
        </div>
      </template>
    </el-page-header>
    <div class="subtitle-container">
      <p class="subtitle">专业的彩票数据分析工具</p>
    </div>

    <!-- 彩票种类选择区域 -->
    <el-card class="lottery-types" shadow="never">
      <h2 class="section-title">选择彩票种类</h2>
      
      <div class="lottery-options">
        <!-- 中国福彩 -->
        <div class="lottery-category">
          <h3 class="category-title">中国福彩</h3>
          <div class="lottery-category-options">
            <!-- 双色球 -->
            <div 
              class="lottery-option" 
              :class="{ active: currentLotteryType === 'ssq' }" 
              @click="switchLotteryType('ssq')"
            >
              <div class="lottery-option-image">
                <img src="@/assets/shuangseqiu.png" alt="双色球" />
              </div>
              <div class="lottery-option-name">双色球</div>
            </div>

            <!-- 福彩3D -->
            <div 
              class="lottery-option" 
              @click="switchLotteryType('3d')"
            >
              <div class="lottery-option-image">
                <img src="@/assets/3D.png" alt="福彩3D" />
              </div>
              <div class="lottery-option-name">福彩3D</div>
            </div>

            <!-- 七乐彩 -->
            <div 
              class="lottery-option" 
              @click="switchLotteryType('qlc')"
            >
              <div class="lottery-option-image">
                <img src="@/assets/7lecai.png" alt="七乐彩" />
              </div>
              <div class="lottery-option-name">七乐彩</div>
            </div>

            <!-- 快乐8 -->
            <div 
              class="lottery-option" 
              @click="switchLotteryType('kl8')"
            >
              <div class="lottery-option-image">
                <img src="@/assets/kuaile8.png" alt="快乐8" />
              </div>
              <div class="lottery-option-name">快乐8</div>
            </div>
          </div>
        </div>

        <!-- 中国体彩 -->
        <div class="lottery-category">
          <h3 class="category-title">中国体彩</h3>
          <div class="lottery-category-options">
            <!-- 大乐透 -->
            <div 
              class="lottery-option" 
              @click="switchLotteryType('dlt')"
            >
              <div class="lottery-option-image">
                <img src="@/assets/daletou.png" alt="大乐透" />
              </div>
              <div class="lottery-option-name">大乐透</div>
            </div>

            <!-- 排列3 -->
            <div 
              class="lottery-option" 
              @click="switchLotteryType('pl3')"
            >
              <div class="lottery-option-image">
                <img src="@/assets/pailie3.png" alt="排列3" />
              </div>
              <div class="lottery-option-name">排列3</div>
            </div>

            <!-- 排列5 -->
            <div 
              class="lottery-option" 
              @click="switchLotteryType('pl5')"
            >
              <div class="lottery-option-image">
                <img src="@/assets/pailie5.png" alt="排列5" />
              </div>
              <div class="lottery-option-name">排列5</div>
            </div>

            <!-- 七星彩 -->
            <div 
              class="lottery-option" 
              @click="switchLotteryType('qxc')"
            >
              <div class="lottery-option-image">
                <img src="@/assets/7星彩.png" alt="七星彩" />
              </div>
              <div class="lottery-option-name">七星彩</div>
            </div>
          </div>
        </div>
      </div>
    </el-card>

    <!-- 分析类型选择 - 只有在选择彩票种类后才显示 -->
    <el-card v-if="currentLotteryType" class="analysis-section" shadow="never">
      <h2 class="section-title">选择分析类型</h2>
      <div class="analysis-options">
        <!-- 表相性分析 -->
        <div class="analysis-option" @click="goToAnalysis('table')">
          <div class="analysis-icon">
            <el-icon :size="32"><Grid /></el-icon>
          </div>
          <div class="analysis-name">表相性分析</div>
          <div class="analysis-desc">提供基于最新100期开奖数据的详细表格分析</div>
        </div>

        <!-- 组合性分析 -->
        <div class="analysis-option" @click="goToAnalysis('surface')">
          <div class="analysis-icon">
            <el-icon :size="32"><Box /></el-icon>
          </div>
          <div class="analysis-name">组合性分析</div>
          <div class="analysis-desc">分析号码之间的组合关系和规律</div>
        </div>

        <!-- 活跃性分析 -->
        <div class="analysis-option" @click="goToAnalysis('trend')">
          <div class="analysis-icon">
            <el-icon :size="32"><TrendCharts /></el-icon>
          </div>
          <div class="analysis-name">活跃性分析</div>
          <div class="analysis-desc">分析号码的活跃度和热度趋势</div>
        </div>

        <!-- 接续性分析 -->
        <div class="analysis-option" @click="goToAnalysis('line')">
          <div class="analysis-icon">
            <el-icon :size="32"><Connection /></el-icon>
          </div>
          <div class="analysis-name">接续性分析</div>
          <div class="analysis-desc">分析号码的连续性和接续规律</div>
        </div>
      </div>
    </el-card>

    <!-- 开发中提示 -->
    <div v-if="showTip" class="tip-overlay" @click="hideTip">
      <div class="tip-content" @click.stop>
        <div class="tip-icon">🚧</div>
        <h3>功能开发中</h3>
        <p>该彩票种类的分析功能正在开发中，目前仅支持双色球分析，请稍后再试或选择双色球进行分析。</p>
        <button class="tip-button" @click="hideTip">我知道了</button>
      </div>
    </div>
  </div>
</template>

<script>
import { ElCard, ElIcon, ElPageHeader } from 'element-plus'
import { Grid, Box, TrendCharts, Connection, DataAnalysis as DataAnalysisIcon } from '@element-plus/icons-vue'

export default {
  name: 'DataAnalysis',
  components: {
    ElCard,
    ElIcon,
    ElPageHeader,
    Grid,
    Box,
    TrendCharts,
    Connection,
    DataAnalysis: DataAnalysisIcon
  },
  data() {
    return {
      currentLotteryType: '', // 默认为空，不选择任何彩票
      showTip: false, // 提示框显示状态
    }
  },
  methods: {
    // 返回上一页
    goBack() {
      try {
        // 检查是否有历史记录可以返回
        if (window.history.length > 1) {
      this.$router.go(-1);
        } else {
          // 如果没有历史记录，返回首页
          this.$router.push('/');
        }
      } catch (error) {
        console.error('返回操作失败:', error);
        // 如果出现错误，返回首页
        this.$router.push('/');
      }
    },

    // 切换彩票类型
    switchLotteryType(type) {
      // 只有双色球功能可用，其他彩票类型显示开发中提示
      if (type !== 'ssq') {
        this.showDevelopingTip();
        return;
      }
      
      this.currentLotteryType = type;
    },

    // 跳转到具体分析页面
    goToAnalysis(analysisType) {
      const routes = {
        'table': '/table-analysis',
        'surface': '/surface-analysis',
        'trend': '/trend-analysis',
        'line': '/line-analysis'
      };

      if (routes[analysisType]) {
        this.$router.push({
          path: routes[analysisType],
          query: { lotteryType: this.currentLotteryType }
        });
      }
    },

    // 显示开发中提示
    showDevelopingTip() {
      this.showTip = true;
    },

    // 隐藏提示
    hideTip() {
      this.showTip = false;
    }
  }
}
</script>

<style scoped>
.data-analysis-container {
  padding: 20px 20px 0px 20px;
  background-color: #f0f2f5;
  min-height: calc(100vh - 70px);
}

.toolbar {
  margin-bottom: 15px;
}

.page-header {
  background: linear-gradient(135deg, #3a7bd5, #00d2ff);
  padding: 30px 24px;
  border-radius: 8px;
  margin-bottom: 10px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

:deep(.el-page-header__back .el-icon),
:deep(.el-page-header__back .el-page-header__title) {
  color: white;
}

.header-content {
  display: flex;
  align-items: center;
  color: white;
}

.header-title {
  font-size: 20px;
  font-weight: 600;
}

.subtitle-container {
  text-align: center;
  margin-bottom: 20px;
}

.subtitle {
  font-size: 18px;
  opacity: 0.9;
  color: #333;
  text-align: center;
  width: 100%;
  margin: 0 auto;
  font-weight: 500;
}

.lottery-types, .analysis-section {
  margin-bottom: 20px;
  border-radius: 8px;
  overflow: hidden;
}

/* 彩票类型选择区域 */
.section-title {
  text-align: center;
  color: #333;
  font-size: 20px;
  margin-bottom: 25px;
  font-weight: 600;
}

.lottery-options {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 20px;
}

.lottery-category {
  margin-bottom: 25px;
}

.category-title {
  text-align: left;
  color: #333;
  font-size: 18px;
  margin-bottom: 15px;
  font-weight: 600;
  padding-bottom: 5px;
  border-bottom: 1px solid #f0f0f0;
}

.lottery-category-options {
  display: flex;
  flex-wrap: wrap;
  gap: 15px;
  justify-content: flex-start;
}

.lottery-option {
  width: 100px;
  padding: 15px 10px;
  border-radius: 12px;
  text-align: center;
  background: white;
  border: 1px solid #f0f0f0;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
  transition: all 0.3s;
  cursor: pointer;
}

.lottery-option.active {
  border-color: #4caf50;
  box-shadow: 0 4px 12px rgba(76, 175, 80, 0.2);
  transform: translateY(-2px);
  background-color: #f1f8e9;
}

.lottery-option:hover:not(.active) {
  transform: translateY(-3px);
  box-shadow: 0 8px 15px rgba(0, 0, 0, 0.1);
  border-color: #e0e0e0;
}

.lottery-option-image {
  width: 50px;
  height: 50px;
  margin: 0 auto 10px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.lottery-option-image img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.lottery-option-name {
  font-size: 14px;
  font-weight: 600;
  color: #333;
}

/* 分析选项样式 */
.analysis-options {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px;
  margin-top: 20px;
}

.analysis-option {
  background: white;
  border-radius: 12px;
  padding: 25px 20px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
  transition: all 0.3s ease;
  cursor: pointer;
  text-align: center;
  border: 1px solid #f0f0f0;
}

.analysis-option:hover {
  transform: translateY(-5px);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.1);
}

.analysis-icon {
  margin-bottom: 15px;
  color: #3a7bd5;
}

.analysis-name {
  font-size: 18px;
  font-weight: 600;
  color: #333;
  margin-bottom: 10px;
}

.analysis-desc {
  font-size: 14px;
  color: #666;
  line-height: 1.5;
}

/* 开发中提示框 */
.tip-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.tip-content {
  background: white;
  padding: 30px;
  border-radius: 16px;
  text-align: center;
  max-width: 320px;
  width: 90%;
  box-shadow: 0 15px 30px rgba(0, 0, 0, 0.2);
}

.tip-icon {
  font-size: 40px;
  margin-bottom: 15px;
}

.tip-content h3 {
  font-size: 20px;
  margin-bottom: 10px;
}

.tip-content p {
  color: #666;
  margin-bottom: 20px;
}

.tip-button {
  background: #3a7bd5;
  color: white;
  border: none;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 16px;
  cursor: pointer;
  transition: all 0.2s;
}

.tip-button:hover {
  background: #2c5aa0;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .data-analysis-container {
    padding: 10px 10px 0px 10px;
  }

  .header-title {
    font-size: 18px;
  }
  
  .subtitle {
    font-size: 16px;
  }

  .lottery-category-options {
    justify-content: center;
    gap: 10px;
  }

  .lottery-option {
    width: calc(25% - 10px);
    min-width: 80px;
    padding: 10px 5px;
  }

  .lottery-option-image {
    width: 40px;
    height: 40px;
  }

  .lottery-option-name {
    font-size: 12px;
  }

  .category-title {
    text-align: center;
    font-size: 16px;
  }
  
  .analysis-options {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 480px) {
  .lottery-option {
    width: calc(33% - 10px);
  }
}
</style> 