<template>
  <aside class="events-mini">
    <div class="em-inset">
      <div class="em-label">Upcoming</div>
    </div>
    <div v-if="events?.length" class="em-rows">
      <div v-for="event in events" :key="event._id" class="em-item">
        <div class="em-inset em-item-body">
          <span class="em-date">{{ formatDate(event) }}</span>
          <NuxtLink
            :to="`/events/${event.slug || event._id}`"
            class="em-title"
            >{{ event.title }}</NuxtLink
          >
          <span
            v-if="event.circle"
            class="em-circle"
            :style="{ color: `var(--c-${event.circle})` }"
            >{{ event.circle }}</span
          >
        </div>
      </div>
    </div>
    <div v-else class="em-rows">
      <div class="em-item em-item--plain">
        <div class="em-inset em-empty">No upcoming events</div>
      </div>
    </div>
    <div class="em-inset em-link-wrap">
      <NuxtLink to="/events" class="em-link">All events &rarr;</NuxtLink>
    </div>
  </aside>
</template>

<script setup>
defineProps({
  events: { type: Array, default: () => [] },
});

const formatDate = (event) => {
  if (!event?.startDate) return "";
  return new Date(event.startDate).toLocaleDateString("en-US", {
    month: "short",
    day: "numeric",
    timeZone: event.displayTimezone || "America/Toronto",
  });
};
</script>

<style scoped>
.events-mini {
  box-sizing: border-box;
  align-self: stretch;
  height: 100%;
  min-height: 100%;
  padding: 24px 0;
  border-left: 1px dashed var(--border);
}

.em-inset {
  padding-left: 20px;
  padding-right: 20px;
}

.em-label {
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin-bottom: 12px;
}

.em-item {
  border-bottom: 1px dashed var(--border);
}

.em-rows .em-item:last-child {
  border-bottom: none;
}

.em-item-body {
  padding-top: 8px;
  padding-bottom: 8px;
}

.em-item--plain .em-empty {
  padding-top: 8px;
  padding-bottom: 8px;
}

.em-date {
  font-size: 11px;
  color: var(--text-faint);
  display: block;
}

.em-title {
  font-size: 12px;
  color: var(--text);
  display: block;
  margin-top: 2px;
  text-decoration: none;
}

.em-title:hover {
  color: var(--candle);
}

.em-circle {
  font-size: 10px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-top: 2px;
  display: inline-block;
}

.em-link-wrap {
  margin-top: 12px;
}

.em-link {
  display: inline-block;
  font-size: 11px;
  color: var(--candle);
}

.em-empty {
  font-size: 11px;
  color: var(--text-faint);
}

@media (max-width: 1024px) {
  .events-mini {
    display: none;
  }
}
</style>
