<template>
  <EventFeedback />
</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/feedback-forms/FeedbackForms'

const fetchData = async ({ $route }) => {
  try {
    const { data } = await http.get(`content/${$route.meta.contentType}`, {
      fields: [
        'uuid',
        'title',
        'date',
        'end_date',
        'content_type',
        'slug',
        { feedback_forms: ['custom_form_type', 'component', 'uuid'] },
        ...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: 'EventFeedbackPage',
  components: {
    EventFeedback: withFetch(Container, { size: 'xxl' })(fetchData)
  }
}
</script>
