<script setup lang="ts">
import MatchBetCard from './MatchBetCard.vue';
import saishiImg from '../assets/images/saishi.png';

defineProps<{
  leagueId: string;
  leagueName: string;
  leagueLogoUrl?: string | null;
  expanded: boolean;
  matches: {
    id: string;
    homeTeamName: string;
    awayTeamName: string;
    homeTeamCode?: string;
    awayTeamCode?: string;
    homeTeamLogoUrl?: string | null;
    awayTeamLogoUrl?: string | null;
    startTime: string;
  }[];
}>();

const emit = defineEmits<{ toggle: []; bet: [id: string] }>();
</script>

<template>
  <section class="league-block">
    <button type="button" class="league-row" :aria-expanded="expanded" @click="emit('toggle')">
      <span class="toggle-icon" :class="{ open: expanded }" aria-hidden="true">
        <span class="toggle-mark">{{ expanded ? '−' : '+' }}</span>
      </span>
      <span class="league-title">*{{ leagueName }}</span>
      <img
        :src="leagueLogoUrl || saishiImg"
        alt=""
        class="league-saishi"
      />
    </button>

    <div v-show="expanded" class="match-panel">
      <div class="match-grid">
        <MatchBetCard
          v-for="match in matches"
          :key="match.id"
          :match="match"
          @bet="emit('bet', $event)"
        />
      </div>
    </div>
  </section>
</template>

<style scoped>
.league-block {
  margin-bottom: 10px;
  border: 1px solid #2e2e2e;
  border-radius: 6px;
  overflow: hidden;
  background: #141414;
}

.league-row {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 12px;
  background: none;
  border: none;
  border-radius: 0;
  text-align: left;
  cursor: pointer;
}

.league-row:active {
  opacity: 0.92;
}

.toggle-icon {
  flex-shrink: 0;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #141414;
  border: 1px solid var(--border-gold-soft);
  display: flex;
  align-items: center;
  justify-content: center;
}

.toggle-mark {
  color: var(--primary-light);
  font-size: 17px;
  font-weight: 900;
  line-height: 1;
  margin-top: -1px;
}

.league-title {
  flex: 1;
  font-size: 13px;
  font-weight: 800;
  color: var(--primary-light);
  line-height: 1.35;
  min-width: 0;
}

.league-saishi {
  flex-shrink: 0;
  height: 44px;
  width: auto;
  max-width: 40px;
  object-fit: contain;
  margin-left: 4px;
  padding-left: 10px;
  border-left: 1px solid #2a2a2a;
}

.match-panel {
  padding: 10px 0 4px;
}

.match-grid {
  display: grid;
  grid-template-columns: repeat(1, minmax(0, 1fr));
  gap: 8px;
  padding: 0 4px;
}
</style>
