<template>
  <div
    v-motion
    :initial="{ opacity: 0, y: 20 }"
    :enter="{
      opacity: 1,
      y: 0,
      transition: {
        delay: 400,
        duration: 600,
        type: 'spring',
        stiffness: 200
      }
    }"
    class="events-card"
  >
    <div class="events-header">
      <div class="header-left">
        <v-icon color="error" size="20">mdi-calendar</v-icon>
        <h3 class="events-title">Upcoming Events</h3>
      </div>
      <v-btn
        variant="text"
        color="error"
        size="small"
        @click="$emit('view-all')"
      >
        View All
        <v-icon end size="16">mdi-arrow-right</v-icon>
      </v-btn>
    </div>

    <div class="events-list">
      <div
        v-for="(event, index) in events"
        :key="event.id"
        v-motion
        :initial="{ opacity: 0, x: -20 }"
        :enter="{
          opacity: 1,
          x: 0,
          transition: {
            delay: 500 + (index * 100),
            duration: 500,
            type: 'spring'
          }
        }"
        class="event-item"
        :class="{ 'event-item--pending': event.status === 'pending' }"
      >
        <div class="event-date">
          <div class="date-month">{{ formatMonth(event.date) }}</div>
          <div class="date-day">{{ formatDay(event.date) }}</div>
        </div>
        
        <div class="event-details">
          <h4 class="event-name">{{ event.title }}</h4>
          <div class="event-meta">
            <span class="event-time">
              <v-icon size="14" color="grey">mdi-clock-outline</v-icon>
              {{ event.time }}
            </span>
            <span class="event-location">
              <v-icon size="14" color="grey">mdi-map-marker</v-icon>
              {{ event.location }}
            </span>
          </div>
        </div>

        <div class="event-status">
          <v-chip
            :color="event.status === 'confirmed' ? 'success' : 'warning'"
            size="x-small"
            variant="tonal"
          >
            {{ event.status }}
          </v-chip>
        </div>
      </div>
    </div>

    <div class="events-footer">
      <div class="footer-message">
        <v-icon size="16" color="grey">mdi-information</v-icon>
        <span>{{ events.length }} upcoming event{{ events.length !== 1 ? 's' : '' }}</span>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { computed } from 'vue';

interface Event {
  id: string;
  title: string;
  date: string;
  time: string;
  location: string;
  status: 'confirmed' | 'pending';
}

interface Props {
  events: Event[];
}

const props = defineProps<Props>();

const emit = defineEmits<{
  'view-all': [];
}>();

// Computed stats
const confirmedCount = computed(() => 
  props.events.filter(e => e.status === 'confirmed').length
);

const pendingCount = computed(() => 
  props.events.filter(e => e.status === 'pending').length
);

// Date formatting
const formatMonth = (dateString: string) => {
  return new Date(dateString).toLocaleDateString('en-US', { month: 'short' }).toUpperCase();
};

const formatDay = (dateString: string) => {
  return new Date(dateString).getDate();
};
</script>

<style scoped lang="scss">
.events-card {
  height: 100%;
  background: linear-gradient(135deg, 
    rgba(255, 255, 255, 0.95),
    rgba(255, 255, 255, 0.85)
  );
  backdrop-filter: blur(30px);
  -webkit-backdrop-filter: blur(30px);
  border-radius: 1.25rem;
  border: 1px solid rgba(255, 255, 255, 0.3);
  box-shadow: 
    0 20px 40px rgba(0, 0, 0, 0.08),
    inset 0 1px 0 rgba(255, 255, 255, 0.6);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
}

.events-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.events-title {
  font-size: 1.125rem;
  font-weight: 600;
  color: rgb(31, 41, 55);
  margin: 0;
}

.events-list {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  overflow-y: auto;
  padding-right: 0.5rem;
  
  &::-webkit-scrollbar {
    width: 4px;
  }
  
  &::-webkit-scrollbar-track {
    background: rgba(220, 38, 38, 0.05);
    border-radius: 2px;
  }
  
  &::-webkit-scrollbar-thumb {
    background: rgba(220, 38, 38, 0.2);
    border-radius: 2px;
    
    &:hover {
      background: rgba(220, 38, 38, 0.3);
    }
  }
}

.event-item {
  display: flex;
  gap: 1rem;
  padding: 1rem;
  background: linear-gradient(135deg, 
    rgba(255, 255, 255, 0.8),
    rgba(255, 255, 255, 0.6)
  );
  border-radius: 0.75rem;
  border: 1px solid rgba(255, 255, 255, 0.5);
  transition: all 0.3s ease;
  cursor: pointer;
  
  &:hover {
    transform: translateX(4px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.08);
    border-color: rgba(220, 38, 38, 0.2);
  }
  
  &--pending {
    opacity: 0.8;
    border-style: dashed;
  }
}

.event-date {
  flex-shrink: 0;
  width: 48px;
  height: 48px;
  background: linear-gradient(135deg, #dc2626, #b91c1c);
  border-radius: 0.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: white;
  box-shadow: 0 4px 12px rgba(220, 38, 38, 0.3);
}

.date-month {
  font-size: 0.625rem;
  font-weight: 600;
  letter-spacing: 0.05em;
}

.date-day {
  font-size: 1.25rem;
  font-weight: 700;
  line-height: 1;
}

.event-details {
  flex: 1;
  min-width: 0;
}

.event-name {
  font-size: 0.875rem;
  font-weight: 600;
  color: rgb(31, 41, 55);
  margin: 0 0 0.25rem 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.event-meta {
  display: flex;
  gap: 1rem;
  font-size: 0.75rem;
  color: rgb(107, 114, 128);
  
  span {
    display: flex;
    align-items: center;
    gap: 0.25rem;
  }
}

.event-status {
  flex-shrink: 0;
  align-self: center;
}

.events-footer {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid rgba(220, 38, 38, 0.1);
}

.footer-message {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  font-size: 0.8125rem;
  color: rgb(107, 114, 128);
}

@media (max-width: 640px) {
  .event-meta {
    flex-direction: column;
    gap: 0.25rem;
  }
}
</style>