<template>
  <div
    class="class-event-card"
    :class="{ 'class-event-card--compact': compact }"
    @click.stop="$emit('click', classItem)"
  >
    <div class="class-event-card__title">{{ classItem.title }}</div>

    <div class="class-event-card__row">
      <q-icon name="mdi-map-marker-outline" size="14px" />
      <span>{{ classItem.room }}</span>
    </div>

    <div class="class-event-card__row">
      <q-icon name="mdi-account-outline" size="14px" />
      <span>{{ classItem.instructor }}</span>
    </div>

    <div class="class-event-card__row">
      <q-icon name="mdi-clock-outline" size="14px" />
      <span>{{ timeRange }}</span>
    </div>

    <div class="class-event-card__row">
      <q-icon name="mdi-account-group-outline" size="14px" />
      <span>{{ enrollment }}</span>
    </div>
  </div>
</template>

<script setup>
import { computed } from "vue";
import { format, parseISO } from "date-fns";

const props = defineProps({
  classItem: { type: Object, required: true },
  compact: { type: Boolean, default: false },
});

defineEmits(["click"]);

const timeRange = computed(() => {
  const start = format(parseISO(props.classItem.date_time_start), "HH:mm");
  const end = format(parseISO(props.classItem.date_time_end), "HH:mm");
  return `${start} - ${end}`;
});

const enrollment = computed(() => {
  const pad = (n) => String(n ?? 0).padStart(2, "0");
  // presentes / total de alunos com contrato ativo no pacote
  return `${pad(props.classItem.present_count)}/${pad(props.classItem.students_count)}`;
});
</script>

<style scoped>
.class-event-card {
  background: #ffffff;
  border-radius: 8px;
  padding: 8px 10px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  transition: box-shadow 0.18s ease, transform 0.18s ease;
}

.class-event-card:hover {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.18);
  transform: translateY(-1px);
}

.class-event-card__title {
  font-size: 12px;
  font-weight: 600;
  color: #003e29;
  text-align: center;
  line-height: 1.15;
  margin-bottom: 2px;
}

.class-event-card__row {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: #505050;
  align-self: flex-start;
}

.class-event-card__row .q-icon {
  color: #ff8340;
  flex-shrink: 0;
}

.class-event-card--compact {
  padding: 6px 8px;
}

.class-event-card--compact .class-event-card__title {
  font-size: 11px;
}

.class-event-card--compact .class-event-card__row {
  font-size: 10px;
}
</style>
