<template>
  <div v-if="upcomingGames.length" class="game-cards">
    <div class="game-card" v-for="(game, index) in upcomingGames" :key="index">
      <div class="icon-top-right">
        <i class="fa-solid fa-volleyball"></i>
      </div>
      <h3>{{ formatDate(game.date) }} - Spiel {{ game.gameNr }}</h3>
      <div class="teams">
        <div class="team">
          <i :class="getIconClass(game.team1)"></i>
          <p>{{ game.team1 }}</p>
        </div>
        <p class="versus">VS</p>
        <div class="team">
          <i :class="getIconClass(game.team2)"></i>
          <p>{{ game.team2 }}</p>
        </div>
      </div>
      <p class="host">
        <strong>Gastgeber:</strong>
        {{ game.host === 1 ? game.team1 : game.team2 }}
      </p>
    </div>
  </div>
  <p v-else>No upcoming games</p>
</template>

<script>
export default {
  props: {
    games: {
      type: Array,
      required: true,
    },
  },
  computed: {
    upcomingGames() {
      const today = new Date();
      return this.games.filter((game) => {
        const gameDate = new Date(game.date);
        return gameDate >= today;
      });
    },
  },
  methods: {
    getIconClass(team) {
      return team === "DJK Saarbrücken-Rastpfuhl"
        ? "fas fa-trophy"
        : "fas fa-poo";
    },
    formatDate(dateStr) {
      const date = new Date(dateStr);
      return date.toLocaleDateString(undefined, {
        year: "numeric",
        month: "long",
        day: "numeric",
      });
    },
  },
};
</script>

<style scoped>
* {
  box-sizing: border-box;
}

.games {
  margin-top: 40px;
  text-align: center;
  padding: 0 15px;
}

h2 {
  color: #34495e;
  margin-bottom: 20px;
  font-size: 2em;
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: 2px;
  text-align: center;
}

.game-cards {
  display: flex;
  flex-direction: column;
  gap: 20px;
  align-items: center;
  width: 100%;
  justify-content: center;
}

.game-card {
  background: linear-gradient(145deg, #dfe4ea, #f1f2f6);
  padding: 20px;
  border-radius: 12px;
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);
  width: 100%;
  max-width: 600px;
  text-align: left;
  position: relative;
  overflow: hidden;
  margin: 0 auto;
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.game-card::before {
  content: "";
  position: absolute;
  top: -40px;
  right: -40px;
  width: 100px;
  height: 100px;
  background-color: rgba(0, 123, 255, 0.15);
  border-radius: 50%;
  z-index: 1;
}

.game-card:hover {
  transform: translateY(-10px);
  box-shadow: 0 15px 30px rgba(0, 0, 0, 0.15);
}

.icon-top-right {
  position: absolute;
  top: 10px;
  right: 10px;
  font-size: 1.8em;
  color: #2980b9;
  opacity: 0.7;
}

.game-card h3 {
  color: #16a085;
  font-size: 1.3em;
  z-index: 2;
  position: relative;
}

.teams {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 20px 0;
  z-index: 2;
  position: relative;
}

.team {
  display: flex;
  align-items: center;
  font-size: 1.1em;
  width: 40%;
}

.team i {
  margin-right: 10px;
  font-size: 1.5em;
  color: #2980b9; /* Color of the icon */
}
.team span {
  margin-right: 10px;
  font-size: 1.5em;
}

.versus {
  font-size: 1.2em;
  color: #e74c3c;
  font-weight: bold;
  z-index: 2;
  width: 20%;
  text-align: center;
}

.host {
  font-weight: bold;
  font-size: 1.1em;
  color: #2980b9;
  z-index: 2;
  position: relative;
}

@media (max-width: 768px) {
  .game-cards {
    width: 100%;
    padding: 0 15px;
    justify-content: center;
  }

  .game-card {
    max-width: 100%;
    margin: 0 auto;
  }

  h2 {
    font-size: 1.8em;
  }

  .teams {
    flex-direction: column;
    align-items: center;
    gap: 10px;
  }

  .team,
  .versus {
    width: 100%;
    text-align: center;
  }

  .icon-top-right {
    font-size: 1.5em;
  }

  .game-card h3 {
    font-size: 1.2em;
  }
}
</style>
