<template>
  <Button
    v-bind="{ ...item }"
    @click="handlePrint"
    :title="$t('header.print')">
    <Print />
  </Button>
</template>

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

  const toolMode = computed(() => useViewer.getToolMode)
  const compareMode = computed(() => useViewer.getCompareMode)

  const handlePrint = async() => {
    if (toolMode.value === 'compare' && compareMode.value === 'content') {
      useViewer.openElement('printSettingDialog')
      return
    }
    useViewer.setDownloading(true)
    try {
      const res = await core.webViewerNamedAction('Print')
      useViewer.setDownloading(false)
      // debugger
      if (!res) {
        useViewer.setDownloadError('Print')
      }
    } catch (error) {
      console.log(error)
    }
  }
</script>

