'use client'; import React, { useState, useEffect } from 'react'; import QRCode from 'qrcode'; import { Smartphone, Sparkles, Copy, Check, ExternalLink, ShieldCheck, Zap, Star, Layers, CheckCircle2, Gift, ArrowRight } from 'lucide-react'; import { ToolItem, AppItem, resolveLocalised } from '@/types'; interface PostResultAppHandoffProps { tool: ToolItem; app?: AppItem | null; locale?: string; hasDownloaded?: boolean; variant?: 'post-result' | 'landing'; } export function PostResultAppHandoff({ tool, app, locale = 'en', hasDownloaded = false, variant = 'post-result', }: PostResultAppHandoffProps) { const [qrDataUrl, setQrDataUrl] = useState(''); const [copiedPromo, setCopiedPromo] = useState(false); const [copiedLink, setCopiedLink] = useState(false); const [origin, setOrigin] = useState(''); useEffect(() => { if (typeof window !== 'undefined') { setOrigin(window.location.origin); } }, []); // Standard fallback app profile if none provided const appData: AppItem = app || { id: 'portrait-app', slug: 'portrait-app', status: 'published', name: { en: 'Portrait Studio AI', hi: 'पोर्ट्रेट स्टूडियो एआई' }, tagline: { en: 'Natural professional portrait retouching in your pocket', hi: 'आपकी जेब में प्राकृतिक पेशेवर पोर्ट्रेट संपादन' }, description: { en: 'The all-in-one portrait perfection suite.', hi: 'सर्वश्रेष्ठ पोर्ट्रेट संपादन ऐप।' }, stores: { android: { packageId: 'com.creinnovations.portraitpro', url: 'https://play.google.com/store/apps/details?id=com.creinnovations.portraitpro', }, ios: { appId: '1672384910', url: 'https://apps.apple.com/app/id1672384910', }, }, tools: [tool.id], rating: { value: 4.8, count: 28400, source: 'App Store & Google Play', }, welcomeBonus: { code: 'TRYWEB50', title: '50 Free Pro Credits', description: 'Install through this link to claim 50 free HD export credits.', }, features: [ 'Unlimited 4K batch processing for full galleries', 'Lossless RAW & Ultra-HD PNG export without compression', 'Instant offline on-device GPU inference', 'Exclusive pro retouching & neural enhancement styles', ], }; const appName = resolveLocalised(appData.name, locale); const appTagline = resolveLocalised(appData.tagline, locale); const bonusCode = appData.welcomeBonus?.code || 'TRYWEB50'; const baseHost = origin || 'http://localhost:3000'; const targetUrl = `${baseHost}/go/${tool.slug}/${appData.slug}?promo=${bonusCode}&src=${variant}`; const iosUrl = appData.stores?.ios?.url || `/go/${tool.slug}/${appData.slug}?promo=${bonusCode}&src=ios`; const androidUrl = appData.stores?.android?.url || `/go/${tool.slug}/${appData.slug}?promo=${bonusCode}&src=android`; // Generate dynamic QR Code for instant phone handoff useEffect(() => { QRCode.toDataURL(targetUrl, { width: 240, margin: 1, color: { dark: '#0f172a', light: '#ffffff', }, }) .then((url) => setQrDataUrl(url)) .catch((err) => console.error('Failed to generate QR code:', err)); }, [targetUrl]); const handleCopyPromo = (e: React.MouseEvent) => { e.stopPropagation(); navigator.clipboard.writeText(bonusCode); setCopiedPromo(true); setTimeout(() => setCopiedPromo(false), 2200); }; const handleCopyLink = (e: React.MouseEvent) => { e.stopPropagation(); navigator.clipboard.writeText(targetUrl); setCopiedLink(true); setTimeout(() => setCopiedLink(false), 2200); }; return (
{/* Post-Download Celebratory Toast (if user clicked download) */} {hasDownloaded && (
HD result saved! Need to edit more photos? Get {appName} for unlimited 4K batch processing.
50 CREDITS UNLOCKED
)} {/* Primary Conversion Header */}
{/* Rating & Bonus Pill */}
{appData.rating?.value || 4.8}
| Official Mobile App | 50 Free Bonus Credits

{variant === 'post-result' ? `Love this result? Take it further in ${appName}` : `Experience ${tool.name ? resolveLocalised(tool.name, locale) : 'Photo Tools'} in ${appName}`}

The web studio is limited to 5 single-photo tries daily. Install our native mobile app to process full photo galleries in 4K lossless resolution with zero wait times.

{/* Voucher Code Box */}
Welcome Voucher
{bonusCode}
{/* Main Grid: Features vs Installation Options */}
{/* Left Column: Why Upgrade to App (Perks List) */}
Why creators use the mobile app:
Unlimited 4K Batch Runs

Edit 50+ photos at once with zero web limits or queues.

Lossless RAW Quality

Retain original camera sensor megapixels and skin textures.

Instant On-Device GPU

Hardware neural acceleration for sub-second offline edits.

100% Private & Ad-Free

No telemetry, no watermarks, and zero cloud photo storage.

{/* Direct Store Download Action Buttons */}
Direct store download links:
{/* Apple App Store Official Badge Button */}
Download on the App Store
{/* Google Play Official Badge Button */}
GET IT ON Google Play
{/* Copy Direct Link */}
{/* Right Column: Scan with Camera QR Code Card */}
Scan with Phone Camera
{/* QR Code Canvas/Image */}
{qrDataUrl ? ( // eslint-disable-next-line @next/next/no-img-element {`Scan ) : (
Generating QR...
)}

Instantly opens App Store or Google Play with promo code {bonusCode} applied.

Works on iOS 15+ and Android 9+
); }