bettersight-statement-extra.../frontend/src/components/SourceDocumentPanel.vue

51 lines
2.2 KiB
Vue

<script setup>
/**
* SourceDocumentPanel.vue
*
* The Source Document card: a PDF gets the browser's native viewer (with
* its own zoom toolbar) in an iframe; an image has no such chrome, so it
* gets its own zoomable/scrollable panel instead - see useImageZoom.js.
* Before any file is chosen, shows an empty-state message instead - this
* panel is always visible (not gated on an extraction result existing),
* so the opening/closing balance fields in TransactionsTable are
* reachable before clicking Extract.
*
* Data flow:
* previewUrl (string|null) - blob URL for the chosen file
* isImage (boolean) - whether to render the image panel instead of the iframe
*/
import { computed } from 'vue'
import { useImageZoom } from '../composables/useImageZoom'
const props = defineProps({
previewUrl: { type: String, default: null },
isImage: { type: Boolean, default: false },
})
const { imgRef, wrapRef, zoomLevelText, onImageLoad, zoomIn, zoomOut, resetZoom } = useImageZoom()
// #toolbar=1 forces the browser's native PDF viewer toolbar (page nav +
// zoom controls) on; navpanes=0 skips the thumbnails/bookmarks sidebar
// so the toolbar isn't competing for space in a narrow column.
const pdfSrc = computed(() => (props.previewUrl ? props.previewUrl + '#toolbar=1&navpanes=0&view=FitH' : ''))
</script>
<template>
<div class="pdf-col-head">
<h2>Source Document</h2>
<div v-if="isImage" class="img-zoom-controls">
<button type="button" title="Zoom out" @click="zoomOut"><i class="fa-solid fa-magnifying-glass-minus"></i></button>
<span>{{ zoomLevelText }}</span>
<button type="button" title="Zoom in" @click="zoomIn"><i class="fa-solid fa-magnifying-glass-plus"></i></button>
<button type="button" id="imgZoomReset" title="Reset zoom to fit" @click="resetZoom"><i class="fa-solid fa-compress"></i> Fit</button>
</div>
</div>
<div v-if="!previewUrl" class="empty-panel empty-panel-source">
<p>No Source Document to Display.<br>Upload one to get started.</p>
</div>
<iframe v-else-if="!isImage" :src="pdfSrc" title="Statement PDF preview"></iframe>
<div v-else ref="wrapRef" class="img-preview-wrap">
<img ref="imgRef" :src="previewUrl" alt="Statement image preview" @load="onImageLoad">
</div>
</template>