<template>
  <view class="event-detail-page">
    <!-- 赛事标题和信息 -->
    <view class="event-header">
      <view class="event-title">{{ eventInfo.title }}</view>
      <view class="divider"></view>
      <view class="event-info">
        <text class="label">地点：</text>
        <text class="value">{{ eventInfo.location }}</text>
      </view>
      <view class="event-info">
        <text class="label">报名时间：</text>
        <text class="value">{{ eventInfo.registerTime }}</text>
      </view>
      <view class="event-info">
        <text class="label">比赛时间：</text>
        <text class="value">{{ eventInfo.matchTime }}</text>
      </view>
      <view class="event-info">
        <text class="label">报名人数：</text>
        <text class="value">{{ eventInfo.registerCount }}</text>
      </view>
      <view class="divider"></view>
    </view>

    <!-- 功能网格 -->
    <view class="function-grid">
      <view class="function-item" @click="handleFunction('info')">
        <view class="function-icon" style="background-color: #C93639;">
          <text>📄</text>
        </view>
        <text class="function-text">信息发布</text>
      </view>
      <view class="function-item" @click="handleFunction('rules')">
        <view class="function-icon" style="background-color: #C93639;">
          <text>📋</text>
        </view>
        <text class="function-text">赛事规程</text>
      </view>
      <view class="function-item" @click="handleFunction('schedule')">
        <view class="function-icon" style="background-color: #C93639;">
          <text>📅</text>
        </view>
        <text class="function-text">活动日程</text>
      </view>
      <view class="function-item" @click="handleFunction('players')">
        <view class="function-icon" style="background-color: #C93639;">
          <text>👥</text>
        </view>
        <text class="function-text">参赛选手</text>
      </view>
      <view class="function-item" @click="handleFunction('match')">
        <view class="function-icon" style="background-color: #C93639;">
          <text>📹</text>
        </view>
        <text class="function-text">比赛实况</text>
      </view>
      <view class="function-item" @click="handleFunction('lineup')">
        <view class="function-icon" style="background-color: #C93639;">
          <text>📝</text>
        </view>
        <text class="function-text">出场顺序</text>
      </view>
      <view class="function-item" @click="handleFunction('score')">
        <view class="function-icon" style="background-color: #C93639;">
          <text>📊</text>
        </view>
        <text class="function-text">成绩</text>
      </view>
      <view class="function-item" @click="handleFunction('awards')">
        <view class="function-icon" style="background-color: #C93639;">
          <text>🏆</text>
        </view>
        <text class="function-text">奖牌榜</text>
      </view>
      <view class="function-item" @click="handleFunction('photos')">
        <view class="function-icon" style="background-color: #C93639;">
          <text>🖼</text>
        </view>
        <text class="function-text">图片直播</text>
      </view>
    </view>

    <!-- 报名按钮 -->
    <view class="register-btn-wrapper" v-if="eventInfo.status === 'open'">
      <view class="register-btn" @click="goToRegister">去报名</view>
    </view>

    <!-- 报名已结束状态 -->
    <view class="register-btn-wrapper" v-if="eventInfo.status === 'finished'">
      <view class="register-btn disabled">报名已结束</view>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      eventInfo: {
        id: 1,
        title: '2025年全国武术散打锦标赛暨第十七届世界武术锦标赛选拔赛',
        location: '天津市-天津市体育中心',
        registerTime: '2025.02.01-2025.02.10',
        matchTime: '2025.02.01-2025.02.10',
        registerCount: '25212',
        status: 'open' // open, finished
      }
    };
  },
  onLoad(options) {
    if (options.id) {
      this.loadEventDetail(options.id);
    }
  },
  methods: {
    loadEventDetail(id) {
      // 加载赛事详情
      // 实际应该从后端获取
    },
    handleFunction(type) {
      const routeMap = {
        'info': '/pages/event-info/event-info',
        'rules': '/pages/event-rules/event-rules',
        'schedule': '/pages/event-schedule/event-schedule',
        'players': '/pages/event-players/event-players',
        'match': '/pages/event-live/event-live',
        'lineup': '/pages/event-lineup/event-lineup',
        'score': '/pages/event-score/event-score',
        'awards': '/pages/event-medals/event-medals',
        'photos': '' // 图片直播暂未实现
      };

      const url = routeMap[type];
      if (url) {
        uni.navigateTo({ url });
      } else {
        uni.showToast({
          title: '功能开发中',
          icon: 'none'
        });
      }
    },
    goToRegister() {
      uni.navigateTo({
        url: '/pages/register-type/register-type?id=' + this.eventInfo.id
      });
    }
  }
};
</script>

<style lang="scss" scoped>
.event-detail-page {
  min-height: 100vh;
  background-color: #f5f5f5;
  padding-bottom: 180rpx;
}

.event-header {
  background-color: #fff;
  padding: 30rpx;
  margin-bottom: 20rpx;
}

.event-title {
  font-size: 36rpx;
  font-weight: bold;
  color: #333333;
  line-height: 1.5;
  margin-bottom: 20rpx;
}

.divider {
  height: 6rpx;
  background-color: #C93639;
  width: 120rpx;
  margin: 30rpx 0;
}

.event-info {
  display: flex;
  margin-bottom: 15rpx;
}

.label {
  font-size: 28rpx;
  color: #666666;
  flex-shrink: 0;
}

.value {
  font-size: 28rpx;
  color: #666666;
}

.function-grid {
  background-color: #fff;
  padding: 30rpx;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 40rpx 30rpx;
}

.function-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 15rpx;
}

.function-icon {
  width: 120rpx;
  height: 120rpx;
  border-radius: 16rpx;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 60rpx;
}

.function-text {
  font-size: 26rpx;
  color: #333333;
  text-align: center;
}

.register-btn-wrapper {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 30rpx;
  background-color: #fff;
  box-shadow: 0 -4rpx 20rpx rgba(0, 0, 0, 0.05);
}

.register-btn {
  background-color: #C93639;
  color: #fff;
  text-align: center;
  padding: 30rpx;
  border-radius: 12rpx;
  font-size: 32rpx;
  font-weight: bold;
}

.register-btn.disabled {
  background-color: #999999;
}
</style>
