33 lines
1.4 KiB
TypeScript
33 lines
1.4 KiB
TypeScript
import * as Print from 'expo-print';
|
||
import * as Sharing from 'expo-sharing';
|
||
import { Platform } from 'react-native';
|
||
|
||
export async function sharePurchaseOfferPdf(params: {
|
||
propertyTitle: string;
|
||
address: string;
|
||
maxBuyPriceEur: number;
|
||
sellerName?: string;
|
||
}): Promise<void> {
|
||
const html = `<!DOCTYPE html><html lang="fr"><head><meta charset="utf-8"/>
|
||
<style>body{font-family:system-ui;padding:32px;color:#111}
|
||
h1{font-size:22px} .box{border:1px solid #ccc;padding:16px;border-radius:8px;margin-top:16px}
|
||
</style></head><body>
|
||
<h1>Offre d'achat — ${escape(params.propertyTitle)}</h1>
|
||
<p>${escape(params.address)}</p>
|
||
<div class="box">
|
||
<p>Montant de l'offre : <strong>${params.maxBuyPriceEur.toLocaleString('fr-FR')} €</strong></p>
|
||
<p>(${params.sellerName ? `Destinataire : ${escape(params.sellerName)}` : 'À compléter'})</p>
|
||
</div>
|
||
<p style="margin-top:24px;font-size:11px;color:#666">MDB-PREDATOR — modèle indicatif, valider avec votre notaire / juriste.</p>
|
||
</body></html>`;
|
||
const { uri } = await Print.printToFileAsync({ html });
|
||
if (Platform.OS === 'web') return;
|
||
if (await Sharing.isAvailableAsync()) {
|
||
await Sharing.shareAsync(uri, { mimeType: 'application/pdf', dialogTitle: 'Offre d’achat' });
|
||
}
|
||
}
|
||
|
||
function escape(s: string): string {
|
||
return s.replace(/&/g, '&').replace(/</g, '<').replace(/"/g, '"');
|
||
}
|