import { useState, useCallback } from 'react'; import * as Print from 'expo-print'; import * as FileSystem from 'expo-file-system'; import { CapturedPhoto } from '../types'; export function usePdfGeneration() { const [generating, setGenerating] = useState(false); const generatePdf = useCallback(async (photos: CapturedPhoto[]): Promise => { if (photos.length === 0) return null; setGenerating(true); try { const imagesHtml = photos.map((p) => { const ext = p.filePath.split('.').pop()?.toLowerCase() || 'jpeg'; const mime = ext === 'png' ? 'image/png' : 'image/jpeg'; return `
`; }).join(''); const html = ` ${imagesHtml} `; const { uri } = await Print.printToFileAsync({ html }); return uri; } catch (err) { console.error('PDF generation failed:', err); return null; } finally { setGenerating(false); } }, []); return { generatePdf, generating, }; }