<template>
  <EventParticipants />
</template>

<script>
import { withFetch } from 'inside-collection/hocs'
import { http } from '@inside-library/helpers/Http'
import { insertIf } from '@inside-library/helpers/Arrays'

import Container from '../../components/register-forms/RegisterParticipants'

const fetchData = async ({ $route }) => {
  try {
    const { data } = await http.get(`content/${$route.meta.contentType}`, {
      fields: [
        'uuid',
        'title',
        'slug',
        'content_type',
        { register_forms: ['custom_form_type'] },
        ...insertIf($route.meta.contentType === 'groups_events', {
          groups: ['slug']
        })
      ],
      filters: { 'slug:eq': $route.params.event }
    })

    return data[0]
  } catch (err) {
    throw new Error(err)
  }
}

export default {
  name: 'EventParticipantsPage',
  components: {
    EventParticipants: withFetch(Container, { size: 'xxl' })(fetchData)
  }
}
</script>
