<script setup>
  import { ref, onMounted, computed } from "vue";

  import { useMenuStore } from '../../stores/MenuStore';
  const MenuStore = useMenuStore();
  MenuStore.get_today();


  import EventListingComplete from '../listings/EventListing.vue';
  // import Promo from '../listings/BlueskyLinks.vue';
  import Promo from '../listings/Promo.vue';

  import { useEventsStore } from '../../stores/EventsStore';

  const props = defineProps({
        limit: {
            type: Number,
            require: false
        },
        
        cal: {
          type: String,
          require: true
        }
    })

  const store = useEventsStore();
  store.fetchEvents(props.cal);
  store.fetchPromo(props.cal);
  const events = computed(() => {
    if (store.events.length == 0){
      store.fetchEvents(props.cal);
    }
    return store.events;
  });
  const promo = computed(() => {
    if (store.promo.length == 0){
      store.fetchPromo(props.cal);
    }
    return store.promo;
  });

</script>
        
<template>
  <div v-if="events.length == 0" class="p-8">
    <p class="p-2">Wait for it ...</p>
    <p class="p-2">Or try refreshing, still workin' out a few bugs in the code.</p>
    <p class="p-2">Though give it a moment ... please ...</p>
  </div>
  <div class="md:flex md:flex-wrap lg:flex lg:flex-wrap md:flex md:justify-center lg:flex lg:justify-center z-0">
    <span class="self-stretch" v-for="(item, index) in events">
      <Promo  v-if="(index % 6 == 0) && index != 0 && events.length > 12" :item = promo[(index/6)-1] :index = "(index/6)-1"/>
      <EventListingComplete v-else-if="(index % 6 != 0)" :item = "item" :index = "index" />
      <!-- <EventListingComplete :item = "item" :index = "index" /> -->
    </span>
  </div>  
</template>