'use client' import { useEffect, Suspense } from 'react' import { useAuth } from '@/lib/AuthContext' import { useRouter, useSearchParams } from 'next/navigation' import { Crown, Zap, Check, Loader2 } from 'lucide-react' const TIERS = [ { name: 'Free', price: '$0', period: 'forever', priceId: null, features: [ 'Access to Souq marketplace', 'Nur AI coaching (basic)', 'Forum access', 'FLH wallet & cashouts', ], cta: 'Get Started', href: '/souq', highlighted: false, icon: Zap, }, { name: 'Premium', price: '$5', period: '/month', priceId: 'price_premium_monthly', features: [ 'Everything in Free', 'Nur AI unlimited coaching', 'Scholar personas (Al-Ghazali, Ibn Abbas, Rabia)', 'Priority support', ], cta: 'Subscribe', highlighted: true, icon: Crown, }, { name: 'Pro', price: '$20', period: '/month', priceId: 'price_pro_monthly', features: [ 'Everything in Premium', 'Early access to new features', 'Custom integrations', 'Direct line to the team', ], cta: 'Subscribe', highlighted: false, icon: Crown, }, ] function UpgradeContent() { const { token, loading: authLoading } = useAuth() const router = useRouter() const searchParams = useSearchParams() useEffect(() => { if (!authLoading && !token) router.push('/login') }, [token, authLoading, router]) useEffect(() => { const upgrade = searchParams.get('upgrade') const canceled = searchParams.get('canceled') if (upgrade === 'success') { alert('Welcome to Premium! Your account has been upgraded.') router.replace('/upgrade') } else if (canceled === 'true') { alert('Checkout canceled. Please try again if you changed your mind.') router.replace('/upgrade') } }, [searchParams, router]) const handleSubscribe = async (priceId: string) => { if (!token) return try { const res = await fetch('/api/upgrade/create-checkout', { method: 'POST', headers: { 'Authorization': `Bearer ${token}`, 'Content-Type': 'application/json' }, body: JSON.stringify({ priceId }), }) const data = await res.json() if (res.ok && data.url) { window.location.href = data.url } else { alert(data.error || 'Failed to start checkout') } } catch { alert('Something went wrong. Please try again.') } } if (authLoading) return
Choose the plan that fits your journey