<template>
  <Button @click="download"> {{ $_tr('common.actions.download') }}</Button>
</template>

<script>
import { Button } from 'inside-collection/components'

import DownloadMixin from '@inside-library/mixins/download-file-mixin'

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

export default {
  name: 'ExperienceDownloadButton',
  components: { Button },
  mixins: [DownloadMixin],
  props: {
    uuid: {
      type: String,
      required: true
    }
  },
  methods: {
    async download() {
      try {
        const { path } = await http.get(`experiences/pdf/${this.uuid}`)
        window.open(path, '_blank')
      } catch (err) {
        throw new Error(err)
      }
    }
  }
}
</script>
