<template>
  <Button
    v-bind="{ ...item }"
    @click="handleFlatten">
    <Flatten />
  </Button>
</template>

<script setup>
  import core from '@/core'
  import { useViewerStore } from '@/stores/modules/viewer'
  
  const { item } = defineProps(['item'])
  const useViewer = useViewerStore()

  const { flattenPdfDownload } = core

  const handleFlatten = async () => {
    useViewer.setDownloading(true)
    try {
      const res = await flattenPdfDownload()
      useViewer.setDownloading(false)
      if (!res) {
        useViewer.setDownloadError('Downloaded')
      }
    } catch (error) {
      console.log(error)
    }
  }
</script>

<style lang="scss">
@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}
</style>
