<template>
  <FullAgenda
    v-if="rooms"
    :herited-data="rooms"
    :herited-options="contentType"
    :frequency-enabled="frequencyEnabled"
  />
</template>

<script>
import FullAgenda from '../../../inside-overrides/agenda/FullAgenda'

import { http } from '@inside-library/helpers/Http'

export default {
  name: 'FullAgendaContainer',
  components: {
    FullAgenda
  },
  props: {
    endpoint: {
      type: String,
      default: 'rooms'
    },
    frequencyEnabled: {
      type: Boolean,
      default: true
    }
  },
  data() {
    return {
      rooms: [],
      contentType: {
        content: {
          contentTypes: [this.endpoint]
        }
      }
    }
  },
  async beforeMount() {
    this.rooms = await this.fetchRooms()
  },
  methods: {
    async fetchRooms() {
      try {
        const { data } = await http.get(`content/${this.endpoint}`, {
          fields: [
            'uuid',
            'title',
            'slug',
            'content_type',
            'status',
            'admin',
            'langcode',
            'max_time',
            'min_time',
            'image',
            'weight',
            'default_cooldown',
            {
              rooms_category: {
                fields: ['uuid', 'title', 'color'],
                filters: { 'status:eq': 1 }
              }
            }
          ],
          filters: {
            'status:eq': 1,
            'slug:eq': this.$route.params.slug
          }
        })

        return data
      } catch (err) {
        throw new Error(err)
      }
    }
  }
}
</script>
