'use client'; import React, { useState, useEffect } from 'react'; import { apiFetch } from '@/lib/auth'; import { Lock, CreditCard, CheckCircle2, X, AlertCircle, Zap, Star, Crown, Copy, Check, ExternalLink, ShieldCheck, Building2, Coins, ArrowRight, MessageCircle, Globe, ArrowLeft, Mail, Clock, Sparkles, Send, Upload, FileText } from 'lucide-react'; interface MonetizationOverlayProps { children: React.ReactNode; featureName: string; } const WHATSAPP_PHONE = "2348107791177"; const SUPPORT_EMAIL = "arkilostudios@gmail.com"; const PLAN_METADATA: Record = { basic: { icon: Zap, tag: 'Starter', headline: 'Ideal for solo operators & small tests' }, standard: { icon: Star, tag: 'Most Popular', headline: 'High-volume engine for serious campaigns', popular: true }, premium: { icon: Crown, tag: 'Enterprise', headline: 'Maximum scale with unrestricted power' }, }; // Accurate baseline exchange conversion rates from NGN (base) const EXCHANGE_RATES: Record = { NGN: 1, USD: 1 / 1500, EUR: 1 / 1650, GBP: 1 / 1950, USDT: 1 / 1500, BTC: (1 / 1500) / 65000, SOL: (1 / 1500) / 150, }; // Circular Flag / Currency Badge Component (Renders real vibrant flags on all OS including Windows) const CurrencyFlag: React.FC<{ currency: string }> = ({ currency }) => { switch (currency) { case 'NGN': return ( ); case 'USD': return ( ); case 'GBP': return ( ); case 'EUR': return ( ); case 'USDT': return ( ₮ ); case 'BTC': return ( ₿ ); case 'SOL': return ( ◎ ); default: return ; } }; // Exact Bank Details requested by User const BANK_ACCOUNTS: Record = { NGN: { currency: 'NGN', label: 'Nigerian Naira (NGN)', sublabel: 'Instant Local Bank Transfer', symbol: '₦', details: [ { label: 'Bank Name', value: 'PAGA' }, { label: 'Account Name', value: 'Ademola Adeleye' }, { label: 'Account Number', value: '1391953270', isPrimary: true } ] }, USD: { currency: 'USD', label: 'United States Dollar (USD)', sublabel: 'Fedwire / ACH Domestic & International', symbol: '$', details: [ { label: 'Bank Name', value: 'Lead Bank' }, { label: 'Account Name', value: 'Ademola Victor Adeleye' }, { label: 'Account Number', value: '216157536315', isPrimary: true }, { label: 'Routing Number (ABA)', value: '101019644' }, { label: 'Account Type', value: 'Personal Checking' }, { label: 'Bank Address', value: '9450 Southwest Gemini Drive, Beaverton, OR, 97008, USA' } ] }, GBP: { currency: 'GBP', label: 'British Pound (GBP)', sublabel: 'Faster Payments / BACS Sort Code', symbol: '£', details: [ { label: 'Bank Name', value: 'Banking Circle S.A.' }, { label: 'Account Name', value: 'Bridge Building S.A.' }, { label: 'Account Number', value: '49412630', isPrimary: true }, { label: 'Sort Code', value: '608382' }, { label: 'Account Type', value: 'Business' }, { label: 'Bank Address', value: '2 Boulevard de la Foire, L-1528 Luxembourg' } ] }, EUR: { currency: 'EUR', label: 'Euro (EUR)', sublabel: 'SEPA Direct Credit Transfer & Wire', symbol: '€', details: [ { label: 'Bank Name', value: 'Banking Circle S.A.' }, { label: 'Account Name', value: 'Ademola Victor Adeleye' }, { label: 'Account Number / IBAN', value: 'LU644080000074755809', isPrimary: true }, { label: 'SWIFT / BIC Code', value: 'BCIRLULL' }, { label: 'Account Type', value: 'Personal' }, { label: 'Bank Address', value: '2 Boulevard de la Foire, L-1528 Luxembourg' } ] } }; // Exact Crypto Details requested by User const CRYPTO_WALLETS: Record = { USDT: { key: 'USDT', name: 'Tether USDT', symbol: 'USDT', network: 'TRON (TRC20)', address: 'TCNaMTfadY1KePJ5sVrbu2evFZ9Zu5nfaQ', }, BTC: { key: 'BTC', name: 'Bitcoin', symbol: 'BTC', network: 'Bitcoin Native', address: '1LWf9VhzTsV1aSjd5oJJ152E4wNmkt4XFc', }, SOL: { key: 'SOL', name: 'Solana', symbol: 'SOL', network: 'Solana Mainnet', address: '3fMAT91KZfQAmU8FEEPEYpS1ZxKyDzqg6DtJQoQcJai9', } }; export const MonetizationOverlay: React.FC = ({ children, featureName }) => { const [status, setStatus] = useState(null); const [plans, setPlans] = useState([]); const [loading, setLoading] = useState(true); const [selectedPlan, setSelectedPlan] = useState('standard'); const [couponCode, setCouponCode] = useState(''); const [applying, setApplying] = useState(false); const [msg, setMsg] = useState({ type: '', text: '' }); const [appliedDiscount, setAppliedDiscount] = useState(null); // Payment Modal States const [showPaymentModal, setShowPaymentModal] = useState(false); const [paymentMethod, setPaymentMethod] = useState<'bank' | 'crypto'>('bank'); const [selectedCurrency, setSelectedCurrency] = useState('NGN'); const [selectedCrypto, setSelectedCrypto] = useState('USDT'); const [modalStep, setModalStep] = useState<'details' | 'verify'>('details'); const [senderRef, setSenderRef] = useState(''); const [copiedKey, setCopiedKey] = useState(null); const [copiedNotification, setCopiedNotification] = useState(null); const [receiptFileName, setReceiptFileName] = useState(''); const [receiptPreview, setReceiptPreview] = useState(null); const fetchStatus = async () => { try { const [statusRes, plansRes] = await Promise.all([ apiFetch('/api/monetization/status'), apiFetch('/api/monetization/plans') ]); if (statusRes.ok) { const data = await statusRes.json(); setStatus(data); // Auto-detect currency based on user country const userCountry = (data.country || '').toLowerCase(); if (userCountry.includes('nigeria') || userCountry.includes('ng')) { setSelectedCurrency('NGN'); } else if (userCountry.includes('united kingdom') || userCountry.includes('uk') || userCountry.includes('britain')) { setSelectedCurrency('GBP'); } else if (userCountry.includes('germany') || userCountry.includes('france') || userCountry.includes('spain') || userCountry.includes('italy') || userCountry.includes('europe')) { setSelectedCurrency('EUR'); } else { setSelectedCurrency('USD'); } } if (plansRes.ok) { const pData = await plansRes.json(); const filtered = pData.filter((p: any) => ['basic', 'standard', 'premium'].includes(p.key)); setPlans(filtered); } } catch (e) { console.error("Failed to fetch monetization data", e); } finally { setLoading(false); } }; useEffect(() => { fetchStatus(); }, []); const copyToClipboard = (text: string, key: string, label: string = "Copied to clipboard") => { navigator.clipboard.writeText(text); setCopiedKey(key); setCopiedNotification(label); setTimeout(() => { setCopiedKey(null); setCopiedNotification(null); }, 2200); }; const applyCoupon = async () => { if (!couponCode.trim()) return; setApplying(true); setMsg({ type: '', text: '' }); try { const res = await apiFetch(`/api/monetization/apply-coupon?code=${encodeURIComponent(couponCode.trim())}`, { method: 'POST' }); const data = await res.json(); if (res.ok) { if (data.discount === 'free') { setMsg({ type: 'success', text: '🎉 Free VIP Access Activated! Unlocking workspace...' }); setTimeout(() => window.location.reload(), 1800); } else { setAppliedDiscount(data.new_price); setMsg({ type: 'success', text: data.message }); } } else { setMsg({ type: 'error', text: data.detail || 'Invalid or expired coupon code.' }); } } catch { setMsg({ type: 'error', text: 'Server error. Please try again.' }); } finally { setApplying(false); } }; // Calculate dynamic converted price const getConvertedPrice = (cur: string) => { const plan = plans.find(p => p.key === selectedPlan); const baseNgn = appliedDiscount ?? (plan?.price || 3500); if (cur === 'NGN') return `₦${baseNgn.toLocaleString()}`; if (cur === 'USD') return `$${(baseNgn * EXCHANGE_RATES.USD).toFixed(2)}`; if (cur === 'EUR') return `€${(baseNgn * EXCHANGE_RATES.EUR).toFixed(2)}`; if (cur === 'GBP') return `£${(baseNgn * EXCHANGE_RATES.GBP).toFixed(2)}`; if (cur === 'USDT') return `${(baseNgn * EXCHANGE_RATES.USDT).toFixed(2)} USDT`; if (cur === 'BTC') return `${(baseNgn * EXCHANGE_RATES.BTC).toFixed(6)} BTC`; if (cur === 'SOL') return `${(baseNgn * EXCHANGE_RATES.SOL).toFixed(4)} SOL`; return `${baseNgn}`; }; const handleConfirmPaymentMade = () => { setModalStep('verify'); }; const handleWhatsAppSubmit = async () => { setApplying(true); try { const plan = plans.find(p => p.key === selectedPlan); const planName = plan ? plan.name : selectedPlan; const cur = paymentMethod === 'bank' ? selectedCurrency : selectedCrypto; const convertedAmountStr = getConvertedPrice(cur); // 1. Submit payment request to backend await apiFetch('/api/monetization/submit-payment', { method: 'POST', body: JSON.stringify({ plan_key: selectedPlan, method: paymentMethod, currency: cur, amount: appliedDiscount ?? (plan?.price || 0), proof_details: senderRef.trim() ? `Sender/Ref: ${senderRef.trim()}` : `Manual ${paymentMethod.toUpperCase()} (${cur})` }) }); // 2. Short, crisp, properly formatted message with accurate price const summaryText = `Hello ArkiTel Desk,\n\n` + `I have made payment for the *${planName}* plan (${convertedAmountStr}).\n` + `Username: *${status?.username || 'My Account'}*\n` + (senderRef.trim() ? `Reference / Sender: *${senderRef.trim()}*\n` : '') + `\nPayment receipt is attached below. Kindly verify and activate!`; try { await navigator.clipboard.writeText(summaryText); } catch (err) { } // 3. Open WhatsApp directly to desk phone with clean dynamic text const directWhatsAppUrl = `https://wa.me/${WHATSAPP_PHONE}?text=${encodeURIComponent(summaryText)}`; window.open(directWhatsAppUrl, '_blank'); // 4. Update UI status to Verification Pending setStatus((prev: any) => ({ ...prev, has_proof: true })); setShowPaymentModal(false); setModalStep('details'); } catch (e) { console.error("Payment submission failed", e); } finally { setApplying(false); } }; if (loading) return <>{children}; const isLocked = !status || status?.plan === 'free' || !status?.plan; return (
{/* Page Content underneath: softly blurred & non-interactive when locked */}
{children}
{isLocked && ( <> {/* IN-PAGE LOCK SHOWCASE: Confined strictly within the content container, keeping the sidebar & navbar accessible */}
{/* Subtle dark backdrop over the locked content */}
{/* Modern Showcase Card */}
{/* Header: Clean, Human & High-Contrast */}
Locked Feature • {featureName}

Supercharge Your Automation Fleet

Choose an active tier to unlock {featureName}, run simultaneous campaign dispatches, and lift scraping limits.

{/* Main Content Area */}
{status?.has_proof ? ( /* Verification Pending State */
Receipt Under Review

Verification in Progress

Your payment is registered with our administration desk. Your account will be upgraded within a few minutes.

Open Official WhatsApp Desk
) : ( <> {/* 3-Tier Plan Grid - Equal height, strict no-overlapping borders */}
{plans.map((plan) => { const meta = PLAN_METADATA[plan.key] || { icon: Star, tag: 'Plan', headline: 'Standard Access Plan', popular: false }; const Icon = meta.icon; const isSelected = selectedPlan === plan.key; const perks = typeof plan.perks === 'string' ? JSON.parse(plan.perks) : (plan.perks || []); return ( ); })}
{/* Action Bar: Pay Button & Coupon */}
{/* Primary Pay & Upgrade CTA */} {/* Coupon Input */}
setCouponCode(e.target.value.toUpperCase())} className="flex-1 bg-transparent px-3 py-1.5 text-xs font-medium outline-none text-white placeholder:text-slate-500 tracking-wider uppercase text-center" />
{msg.text && (
{msg.text}
)} {/* Security & Guarantee Trust Bar */}
256-Bit Encrypted Transfer Fast Desk Verification Bank & Crypto Accepted
)}
{/* MODAL: Payment Channels, Bank Accounts & Crypto — Fixed Viewport Centered */} {showPaymentModal && (
{/* Frosted deep dark backdrop over entire screen */}
setShowPaymentModal(false)} /> {/* Centered Modal Container (Side-by-Side 2-Column Desktop Layout) */}
{/* Floating Copied Toast Alert */} {copiedNotification && (
{copiedNotification}
)} {/* Modal Header */}
{/* Back Button */}
{modalStep === 'verify' ? : (paymentMethod === 'bank' ? : )}

{modalStep === 'details' ? 'Payment Checkout' : 'Receipt Verification Desk'} {modalStep === 'details' ? 'Step 1 of 2' : 'Step 2 of 2'}

Plan: {plans.find(p => p.key === selectedPlan)?.name} • Total Due: {getConvertedPrice(paymentMethod === 'bank' ? selectedCurrency : selectedCrypto)}

{/* Close Button */}
{/* Modal Body Container */}
{modalStep === 'details' ? ( /* Side-by-Side: Left Column Fixed, Right Column Scrollable */
{/* Left Column (5 of 12): Channel Switcher, Currency / Token Chips & Order Summary (Fixed on Desktop) */}
{/* 1. Channel Switcher */}
{/* 2. Currency / Coin Selector Chips */} {paymentMethod === 'bank' ? (
2. Choose Currency Direct FX Conversion
{Object.entries(BANK_ACCOUNTS).map(([currKey, acc]) => { const isSel = selectedCurrency === currKey; return ( ); })}
) : (
2. Choose Cryptocurrency On-Chain Transfer
{Object.entries(CRYPTO_WALLETS).map(([cKey, cw]) => { const isSel = selectedCrypto === cKey; return ( ); })}
)} {/* Summary Recap Card */}
Selected Tier {plans.find(p => p.key === selectedPlan)?.name}
Billing Term Monthly Access (30 Days)
Total Due {getConvertedPrice(paymentMethod === 'bank' ? selectedCurrency : selectedCrypto)}
{/* Right Column (7 of 12): Dedicated Scrollable Section on Desktop */}
{/* Prominent Amount Card with 1-Click Copy */}
Exact Amount To Send
{getConvertedPrice(paymentMethod === 'bank' ? selectedCurrency : selectedCrypto)}
{paymentMethod === 'bank' ? BANK_ACCOUNTS[selectedCurrency]?.sublabel : `Network: ${CRYPTO_WALLETS[selectedCrypto]?.network}`}
{/* Bank Accounts Grid with Individual Copy Buttons */} {paymentMethod === 'bank' && (
Destination Account ({BANK_ACCOUNTS[selectedCurrency]?.label})
{BANK_ACCOUNTS[selectedCurrency]?.details.map((field, idx) => (
{field.label} {field.isPrimary && ( Primary )}
{field.value}
))}
)} {/* Crypto Wallet Details */} {paymentMethod === 'crypto' && (() => { const cw = CRYPTO_WALLETS[selectedCrypto]; return (
{/* Network Warning Banner */}
⚠️
Network Verification: Send only {cw.name} on the {cw.network} network. Other networks will result in lost funds.
{/* Deposit Address Box */}
Deposit Address ({cw.network}) {cw.network}
{cw.address}
); })()} {/* Primary "I've Made Payment" CTA */}
) : ( /* Step 2: Luxury Redesigned Receipt Verification Desk */
{/* Stepper Progress Bar */}
✓
Payment Sent
2
Verification Desk
3
Account Active
{/* Luxury Digital Voucher / Clearing Pass */}
{/* Top Holographic Watermark Bar */}
ArkiTel Financial Clearing Voucher
Concierge Active (< 5 min SLA)
{/* Voucher Grid: 4 Core Parameters */}
Selected Tier
{plans.find(p => p.key === selectedPlan)?.name}
Amount Sent
{getConvertedPrice(paymentMethod === 'bank' ? selectedCurrency : selectedCrypto)}
Channel {paymentMethod === 'bank' ? `Bank (${selectedCurrency})` : `Crypto (${selectedCrypto})`}
Account ID @{status?.username || 'Current Operator'}
{/* Perforated Voucher Tear Line */}
{/* Interactive Proof Submission Controls */}
{/* Payer Name / Reference Input */}
Speeds Up Immediate Unlock
setSenderRef(e.target.value)} className="w-full bg-black/50 border border-white/15 focus:border-indigo-500 focus:ring-1 focus:ring-indigo-500/40 rounded-xl px-4 py-3 text-xs sm:text-sm text-white placeholder:text-slate-500 outline-none transition-all font-medium" />
{/* Simulated / Interactive Receipt Dropzone */}
{ if (e.target.files && e.target.files[0]) { const f = e.target.files[0]; setReceiptFileName(f.name); setReceiptPreview(URL.createObjectURL(f)); } }} /> {receiptFileName ? (
{receiptFileName}
Receipt ready for transmission to WhatsApp Desk
) : ( )}
{/* Primary VIP WhatsApp Activation Action */}
{/* Alternative Desks Grid & 1-Click Message Copy */} {/* 1-Click Verification Message Copy */}
Prefer manual chat message?
)}
)} )}
); };