import React, { useMemo, useRef } from 'react'; import { QRCodeSVG, QRCodeCanvas } from 'qrcode.react'; import { MapPin, ScanLine, AlertTriangle, Download } from 'lucide-react'; import { Button } from '@astryxdesign/core/Button'; import { buildStoreQrPayload } from '../services/fiestaApi'; interface StoreQRViewProps { /** Merchant tenant the QR is scoped to. */ tenantId: number; /** Resolved outlet id. When absent/0, the QR can't be scoped to a store. */ locationid?: number; /** Outlet display name (shown on the printable card). */ storeName: string; /** Zone label, e.g. "R.S. Puram, Coimbatore". */ storeZone?: string; /** Full street address, when available. */ storeAddress?: string; } const QR_FG = '#000000'; const QR_BG = '#ffffff'; const QR_MARGIN = 4; const QR_LEVEL = 'Q' as const; export default function StoreQRView({ tenantId, locationid, storeName, storeZone, storeAddress, }: StoreQRViewProps) { const canvasRef = useRef(null); const payload = useMemo( () => (locationid ? buildStoreQrPayload({ tenantid: tenantId, locationid }) : ''), [tenantId, locationid], ); const slug = useMemo(() => { return storeName .toLowerCase() .replace(/[^a-z0-9]+/g, '-') .replace(/^-+|-+$/g, '') || 'store'; }, [storeName]); const downloadPng = () => { const canvas = canvasRef.current; if (!canvas) return; const a = document.createElement('a'); a.href = canvas.toDataURL('image/png'); a.download = `${slug}-qr.png`; a.click(); }; if (!locationid) { return (

No store to encode

This QR opens a specific outlet's storefront, but no outlet is resolved yet. Once a store location is assigned, its scannable code appears here.

); } return (
{/* Premium Table Tent Mockup Card */}
{/* Ambient Background Glow inside card */}
{/* Gradient Header banner */}
Scan & Shop

{storeName}

{(storeZone || storeAddress) && (

{storeZone || storeAddress}

)}
{/* QR Code Frame with Overlap Layout */}
{/* Counter instructions info block */}

Storefront QR Code

Customers scan this using the consumer app to shop this branch.

{/* Download Action Button */}
{/* Hidden high-res canvas — source for the PNG download */}
); }