import { useRef } from 'react'; // @ts-expect-error - qrcode.react doesn't have official TS types import QRCode from 'qrcode.react'; import { Download } from 'lucide-react'; import { useBusinessCard } from '../store/BusinessCardContext'; import styles from './QRCodeDisplay.module.css'; import type { BusinessCard } from '../store/types'; function generateVCard(businessCard: BusinessCard): string { const lines = [ 'BEGIN:VCARD', 'VERSION:3.0', `FN:${businessCard.name}`, `N:${businessCard.name.split(' ').reverse().join(';')}`, `TITLE:${businessCard.title}`, `ORG:${businessCard.company}`, `EMAIL:${businessCard.email}`, `TEL:${businessCard.phone}`, businessCard.website ? `URL:${businessCard.website}` : null, businessCard.image ? `PHOTO;VALUE=URL:${businessCard.image}` : null, 'END:VCARD', ] .filter(Boolean) .join('\r\n'); return lines; } export function QRCodeDisplay() { const { businessCard } = useBusinessCard(); const qrRef = useRef(null); const vCard = generateVCard(businessCard); const handleDownload = () => { const canvas = qrRef.current?.querySelector('canvas'); if (canvas) { const link = document.createElement('a'); link.href = canvas.toDataURL('image/png'); link.download = `${businessCard.name}-contact.png`; link.click(); } }; return (

Scan to Add Contact

Scan with any smartphone camera

); }