<template>
  <div class="cart">
    <template v-if="executedRequest && files">
      <template v-for="file in files">
        <file-paragraph
          v-if="isAlive(file, 'uuid')"
          :key="file.uuid"
          :heritedData="{ file }"
          @removeDocument="removeDocument"
        />
      </template>
    </template>

    <p v-else-if="executedRequest">{{ $_tr('customs.BOOKMARKS.empty') }}</p>
  </div>
</template>

<script>
import FileParagraph from '../../inside-overrides/inside-library/paragraphs/FileParagraph'

export default {
  name: 'bookmarks-customs',
  components: { FileParagraph },
  data() {
    return {
      cartStatus: null,
      files: [],
      executedRequest: false
    }
  },
  mounted() {
    this.getFiles()
  },
  methods: {
    getFiles() {
      this.get(`users/reactions/bookmark/${this.getUserInfos.uuid}`).then(
        res => {
          this.files = res.data ? res.data.data : []
          this.executedRequest = true
        }
      )
    },
    removeDocument(document) {
      const documentIndex = this.files.findIndex(function (element) {
        return element.uuid === document.uuid
      })

      this.files.splice(documentIndex, 1)
    }
  }
}
</script>
