<template>
  <Button
    class="home-ebook-button-container ebook-btn mr-m"
    @click="downloadEbook"
  >
    {{ $_tr('download') }}
  </Button>
</template>

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

import { Button } from 'inside-collection/components'

export default {
  name: 'HomeEbookButton',
  $_i18nRootPath: 'customs.HOME_PAGE.ebook',
  components: {
    Button
  },
  props: {
    brand: {
      type: String
    },
    folder: {
      type: String
    }
  },
  methods: {
    downloadEbook() {
      return new Promise((resolve, reject) => {
        http
          .get('ebook', {
            brand: this.brand,
            folder: this.folder
          })
          .then(({ success }) => {
            this.$_triggerToast({
              type: success ? 'success' : 'error',
              title: this.$_tr(success ? 'inProgress' : 'error'),
              text: ''
            })

            resolve()
          })
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.home-ebook-button-container {
  display: flex;
  justify-content: center;
  margin-left: auto;
}
</style>
