<template>
  <div class="pc-lottery-detail-page">
    <div class="pc-main-container">
      <div class="page-header">
        <div class="header-left" @click="goBack">
          <el-icon :size="20"><ArrowLeft /></el-icon>
          <span class="back-text">{{ t('返回') }}</span>
        </div>
        <h2 class="page-title">{{ lotteryTitle || '开奖详情' }}</h2>
        <div class="header-right"></div>
      </div>

      <div class="component-container">
        <Pc28Component
            v-if="['canada28', 'jisu28'].includes(currentGame)"
            :game="currentGame"
            :params="requestParams"
        />
        <MarkSixComponent
            v-else-if="currentGame === 'lhc'"
            :game="currentGame"
            :params="requestParams"
        />
        <RacingComponent
            v-else-if="currentGame === 'jisu'"
            :game="currentGame"
            :params="requestParams"
        />
        <div v-else class="empty-state">
          {{ t('暂无相关组件') }}
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue';
import { useRoute, useRouter } from 'vue-router';
import { useI18n } from 'vue-i18n';
import { ArrowLeft } from '@element-plus/icons-vue';

import Pc28Component from './components/Pc28Component.vue';
import MarkSixComponent from './components/MarkSixComponent.vue';
import RacingComponent from './components/RacingComponent.vue';

const { t } = useI18n();
const route = useRoute();
const router = useRouter();

const currentGame = ref('');
const lotteryTitle = ref('');
const requestParams = ref({});

const goBack = () => {
  router.back();
};

onMounted(() => {
  const query = route.query;
  currentGame.value = query.game || '';
  lotteryTitle.value = query.name || '';

  if (query.params) {
    try {
      requestParams.value = JSON.parse(decodeURIComponent(query.params));
      console.log(requestParams, 67)
    } catch (error) {
      console.error("解析 params 失败:", error);
    }
  }
});
</script>

<style scoped lang="scss">
.pc-lottery-detail-page {
  width: 100%;
  background-color: #141414;
  display: flex;
  justify-content: center;
  padding: 30px 0;
}

.pc-main-container {
  width: 100%;
  max-width: 1200px;
  padding: 0 20px;
}

.page-header {
  display: flex;
  align-items: center;
  //justify-content: flex-start;
  margin-bottom: 20px;
  height: 50px;
  background-color: #212121;
  padding: 0 20px;
  border-radius: 8px;
  border: 1px solid #333;

  .header-left {
    display: flex;
    align-items: center;
    cursor: pointer;
    color: #fff;
    transition: color 0.3s;
    width: 100px;
    &:hover { color: #f8b932; }
    .back-text { margin-left: 5px; font-size: 15px; }
  }

  .page-title {
    color: #ffffff;
    font-size: 18px;
    font-weight: 600;
    margin: 0;
    margin-left: -20px;
    flex: 1;
    //text-align: center;
  }

  .header-right {
    width: 100px;
  }
}

.component-container {
  background-color: #212121;
  border-radius: 8px;
  min-height: 500px;
  padding: 20px;
  border: 1px solid #333;
}

.empty-state {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 400px;
  color: #888;
}
</style>