<template>
  <Page
    :extra-filters="extraFilters"
    :extra-fields="extraFields"
    :extra-content-root="extraContentRoot"
    :extra-categories-fields="extraCategoriesFields"
    :banner-data="bannerData"
  />
</template>

<script>
import Page from '@inside-news/components/pages/ListingPage'

export default {
  name: 'NewsListingPage',
  components: { Page },
  data() {
    return {
      bannerData: {
        add: ['news', 'forms'],
        page: 'news'
      },
      extraContentRoot: {
        clubs_news: item => ({
          name: 'ClubsNewsPage',
          params: { slug: item.slug[0], clubs_slug: item.clubs.slug[0] }
        })
      },
      extraFields: [
        {
          clubs: ['slug', 'title']
        }
      ],
      extraCategoriesFields: [
        {
          business: {
            fields: ['uuid', 'title'],
            filters: { 'status:eq': 1, sort: 'title:asc' }
          }
        },
        {
          region: {
            fields: ['uuid', 'title'],
            filters: { 'status:eq': 1, sort: 'title:asc' }
          }
        }
      ]
    }
  },
  computed: {
    extraFilters() {
      return [
        {
          id: 'business',
          type: 'selectbox',
          modelName: 'business',
          fetch: true,
          reference: 'business',
          fields: ['uuid', 'title'],
          filters: { 'status:eq': 1, sort: 'title:asc' },
          objectLabelKey: 'title',
          objectValueKey: 'uuid',
          label: this.$_tr('filters.business')
        },
        {
          id: 'region',
          type: 'selectbox',
          modelName: 'region',
          fetch: true,
          reference: 'region',
          fields: ['uuid', 'title'],
          filters: { 'status:eq': 1, sort: 'title:asc' },
          objectLabelKey: 'title',
          objectValueKey: 'uuid',
          label: this.$_tr('filters.region')
        }
      ]
    }
  }
}
</script>
