<script>
import { h } from 'vue'

import { withFetch } from 'inside-collection/hocs'

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

import BulkEditionContainer from '../components/bulk-edition/BulkEditionContainer.vue'

const fetchContents = async ({ $route }) => {
  try {
    const uuids = $route.query.uuids

    const { data } = await http.get(
      'content/rops,sops,documents,declined_documents,procedures',
      {
        filters: {
          'uuid:in': uuids
        },
        fields: ['title', 'uuid', 'content_type']
      }
    )

    return data
  } catch (err) {
    throw new Error(err)
  }
}

export default {
  name: 'BulkEditionPage',
  render() {
    const BulkEdition = withFetch(BulkEditionContainer, { size: 'xxl' })(
      fetchContents
    )

    return h(BulkEdition)
  }
}
</script>
