|
| 1 | +import React from 'react' |
| 2 | +import { STRIPE_CREDIT_URLS } from '@/config/stripe' |
| 3 | +import { CREDIT_TIERS } from '@/config/credits' |
| 4 | + |
| 5 | +interface CreditsModalProps { |
| 6 | + isOpen: boolean |
| 7 | + onClose: () => void |
| 8 | +} |
| 9 | + |
| 10 | +const CreditsModal: React.FC<CreditsModalProps> = ({ isOpen, onClose }) => { |
| 11 | + if (!isOpen) return null |
| 12 | + |
| 13 | + const handlePurchase = (checkoutKey: keyof typeof STRIPE_CREDIT_URLS) => { |
| 14 | + const url = STRIPE_CREDIT_URLS[checkoutKey] |
| 15 | + window.open(url, '_blank', 'noopener,noreferrer') |
| 16 | + } |
| 17 | + |
| 18 | + return ( |
| 19 | + <div className="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 p-4"> |
| 20 | + <div className="bg-white dark:bg-gray-900 rounded-lg shadow-2xl max-w-4xl w-full p-8 fade-in max-h-[90vh] overflow-y-auto"> |
| 21 | + {/* Header */} |
| 22 | + <div className="flex items-center justify-between mb-6"> |
| 23 | + <div> |
| 24 | + <h2 className="text-3xl font-mono font-bold text-electric-teal mb-2"> |
| 25 | + Buy AI Credits |
| 26 | + </h2> |
| 27 | + <p className="text-gray-600 dark:text-gray-400"> |
| 28 | + Top up your credits for code generation and AI assistance |
| 29 | + </p> |
| 30 | + </div> |
| 31 | + <button |
| 32 | + onClick={onClose} |
| 33 | + className="text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200 text-2xl" |
| 34 | + aria-label="Close" |
| 35 | + > |
| 36 | + ✕ |
| 37 | + </button> |
| 38 | + </div> |
| 39 | + |
| 40 | + {/* Credit Tiers */} |
| 41 | + <div className="grid md:grid-cols-3 gap-4 mb-6"> |
| 42 | + {CREDIT_TIERS.map((tier) => ( |
| 43 | + <div |
| 44 | + key={tier.checkoutKey} |
| 45 | + className={`relative border-2 rounded-lg p-6 transition-all ${ |
| 46 | + tier.popular |
| 47 | + ? 'border-electric-teal shadow-lg scale-105' |
| 48 | + : 'border-gray-200 dark:border-gray-700' |
| 49 | + }`} |
| 50 | + > |
| 51 | + {/* Popular Badge */} |
| 52 | + {tier.popular && ( |
| 53 | + <div className="absolute -top-3 left-1/2 transform -translate-x-1/2"> |
| 54 | + <span className="bg-electric-teal text-space-black px-4 py-1 rounded-full text-xs font-mono font-bold whitespace-nowrap"> |
| 55 | + BEST VALUE |
| 56 | + </span> |
| 57 | + </div> |
| 58 | + )} |
| 59 | + |
| 60 | + {/* Credits Amount */} |
| 61 | + <div className="text-center mb-4"> |
| 62 | + <div className="text-4xl font-mono font-bold text-electric-teal mb-1"> |
| 63 | + {tier.credits.toLocaleString()} |
| 64 | + </div> |
| 65 | + <div className="text-sm text-gray-600 dark:text-gray-400"> |
| 66 | + credits |
| 67 | + </div> |
| 68 | + {tier.bonus > 0 && ( |
| 69 | + <div className="mt-2 text-sm text-cyber-violet font-semibold"> |
| 70 | + +{tier.bonus} bonus credits! |
| 71 | + </div> |
| 72 | + )} |
| 73 | + </div> |
| 74 | + |
| 75 | + {/* Price */} |
| 76 | + <div className="text-center mb-4"> |
| 77 | + <span className="text-3xl font-bold">${tier.price}</span> |
| 78 | + <span className="text-gray-500 dark:text-gray-400 ml-1 text-sm"> |
| 79 | + one-time |
| 80 | + </span> |
| 81 | + </div> |
| 82 | + |
| 83 | + {/* Value indicator */} |
| 84 | + <div className="text-center text-xs text-gray-500 dark:text-gray-400 mb-4"> |
| 85 | + ${(tier.price / tier.credits * 100).toFixed(1)}¢ per credit |
| 86 | + </div> |
| 87 | + |
| 88 | + {/* Purchase Button */} |
| 89 | + <button |
| 90 | + onClick={() => handlePurchase(tier.checkoutKey)} |
| 91 | + className={`w-full py-3 rounded-lg font-mono font-semibold transition-colors ${ |
| 92 | + tier.popular |
| 93 | + ? 'bg-electric-teal text-space-black hover:bg-cyber-violet hover:text-white' |
| 94 | + : 'bg-gray-200 dark:bg-gray-800 text-gray-900 dark:text-white hover:bg-electric-teal hover:text-space-black' |
| 95 | + }`} |
| 96 | + > |
| 97 | + Buy Now |
| 98 | + </button> |
| 99 | + </div> |
| 100 | + ))} |
| 101 | + </div> |
| 102 | + |
| 103 | + {/* Footer Info */} |
| 104 | + <div className="border-t border-gray-200 dark:border-gray-700 pt-6"> |
| 105 | + <div className="grid md:grid-cols-3 gap-4 text-xs text-gray-600 dark:text-gray-400"> |
| 106 | + <div> |
| 107 | + <p className="font-semibold mb-1">Do credits expire?</p> |
| 108 | + <p>No, your credits never expire. Use them whenever you need.</p> |
| 109 | + </div> |
| 110 | + <div> |
| 111 | + <p className="font-semibold mb-1">Secure payment</p> |
| 112 | + <p>All payments are securely processed by Stripe.</p> |
| 113 | + </div> |
| 114 | + <div> |
| 115 | + <p className="font-semibold mb-1">Need more?</p> |
| 116 | + <p>Consider a subscription plan for unlimited access.</p> |
| 117 | + </div> |
| 118 | + </div> |
| 119 | + </div> |
| 120 | + </div> |
| 121 | + </div> |
| 122 | + ) |
| 123 | +} |
| 124 | + |
| 125 | +export default CreditsModal |
0 commit comments