<template>
  <div class="duty-container">
    <div class="duty-section">
      <div class="icon-top-right">
        <i class="fa-solid fa-house"></i>
      </div>
      <div class="section-header">
        <h3>Hallendienst</h3>
      </div>
      <ul>
        <li v-for="person in currentDuties.courtDuty" :key="person">
          {{ person }}
        </li>
      </ul>
    </div>
    <div class="duty-section">
      <div class="icon-top-right">
        <i class="fas fa-money-bill-wave"></i>
      </div>
      <div class="section-header">
        <h3>Kassendienst</h3>
      </div>
      <ul>
        <li v-for="person in currentDuties.cashDuty" :key="person">
          {{ person }}
        </li>
      </ul>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    duties: {
      type: Array,
      required: true,
    },
  },
  computed: {
    currentWeek() {
      const currentDate = new Date();
      const start = new Date(currentDate.getFullYear(), 0, 1);
      const diff = currentDate - start;
      const oneWeek = 1000 * 60 * 60 * 24 * 7;
      return Math.ceil(diff / oneWeek);
    },
    currentDuties() {
      return this.duties.find(
        (duty) => duty.week === (this.currentWeek + 6) % this.duties.length
      );
    },
  },
};
</script>

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

.duties {
  text-align: center;
  margin-top: 40px;
  padding: 0 15px; /* Add padding to prevent cut-off */
}

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

.duty-container {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  gap: 20px;
  flex-wrap: wrap;
  width: 100%;
  margin: 0 auto; /* Center the container */
}

.duty-section {
  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: 45%;
  text-align: left;
  position: relative;
  overflow: hidden;
  transition: transform 0.3s ease, box-shadow 0.3s ease;
  margin: 0 auto; /* Center the card */
}

.duty-section::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;
}

.duty-section: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;
}

h3 {
  color: #16a085;
  font-size: 1.5em;
  z-index: 2;
}

ul {
  list-style: none;
  padding: 0;
  z-index: 2;
  position: relative;
}

li {
  background-color: #bdc3c7;
  margin: 5px 0;
  padding: 10px;
  border-radius: 8px;
  font-size: 1.2em;
  transition: background-color 0.2s ease;
}

li:hover {
  background-color: #ecf0f1;
}

@media (max-width: 768px) {
  .duty-container {
    flex-direction: column;
    align-items: center;
    width: 100%;
    padding: 0 15px;
  }

  .duty-section {
    max-width: 100%; /* Take full width on small screens */
    margin: 0 auto; /* Center the card */
  }

  h2 {
    font-size: 1.8em;
  }

  .icon-top-right {
    font-size: 1.5em;
  }
}
</style>
