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

import OffersListingPage from './OffersListingPage'

const fetchOffersListing = async ({ $route }) => {
  const currentRoute = $route.path.replace(/\//, '')
  try {
    const { data } = await http.get('content/custom', {
      filters: {
        'status:eq': 1,
        'slug:eq': currentRoute
      },
      fields: ['uuid', 'title', 'content']
    })
    return data[0]
  } catch (err) {
    throw new Error(err)
  }
}
export default {
  name: 'OffersListingPage',
  $_i18nRootPath: 'customs.OFFERS.LISTING',
  components: {
    OffersListingPageWithData: withFetch(OffersListingPage, {
      watch: true
    })(fetchOffersListing)
  }
}
</script>
