<template>
  <div class="ebook-generation-container">
    <AsyncActionButton class="ebook-btn" icon="pdf-file" @click="downloadEbook">
      {{ $_tr('generate') }}
    </AsyncActionButton>
  </div>
</template>

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

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

export default {
  name: 'DownloadEbookButton',
  $_i18nRootPath: 'customs.DOWNLOAD_EBOOK',
  components: {
    AsyncActionButton
  },
  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>
.ebook-generation-container {
  display: flex;
  justify-content: center;
}
</style>
