<template>
  <Capsule
    v-bind="getAttrs($attrs)"
    :scaffold-overrides="capsuleOverrides"
    :extra-categories-config="m_extraCategoriesConfig"
    :slug="slug"
    :to="{ name: 'NewsPage', params: { slug: slug[0] } }"
  />
</template>

<script>
import { markRaw } from 'vue'

import Capsule from '@inside-news/components/lib/Capsule'
import NewsCriticality from './NewsCriticality'
import newsCategoriesMixin from '../../mixins/news-categories-mixin'

import { getAttrs } from '@inside-library/helpers/Attrs'

export default {
  name: 'CapsuleNews',
  components: { Capsule, NewsCriticality },
  mixins: [newsCategoriesMixin],
  props: {
    slug: {
      type: Array,
      required: true
    }
  },
  methods: {
    getAttrs,
    capsuleOverrides(data, { addItemBefore, deleteItems }) {
      const criticality = data.news_criticalities || {}

      addItemBefore('comments', {
        id: 'criticality',
        class: 'action',
        tag: markRaw(NewsCriticality),
        data: criticality,
        hideIf: () => !criticality.title
      })

      deleteItems('author')
    }
  }
}
</script>
