'use client'; import { useState } from 'react'; import { motion } from 'framer-motion'; import { Wallet, CreditCard, Plus, Check, Zap, Crown, Building2, ArrowRight, Receipt, Download, Clock } from 'lucide-react'; import { useAuth } from '@/lib/contexts/AuthContext'; interface Plan { id: string; name: string; price: number; priceMonthly: number; icon: React.ElementType; color: string; features: string[]; limits: { apiRequests: string; llmRequests: string; storage: string; }; } const plans: Plan[] = [ { id: 'free', name: 'Free', price: 0, priceMonthly: 0, icon: Zap, color: 'text-muted', features: ['Базовый поиск', 'История запросов', 'Ограниченный AI'], limits: { apiRequests: '1,000/день', llmRequests: '50/день', storage: '100 MB', }, }, { id: 'pro', name: 'Pro', price: 990, priceMonthly: 990, icon: Crown, color: 'text-accent', features: ['Расширенный поиск', 'Приоритетный AI', 'Экспорт данных', 'API доступ'], limits: { apiRequests: '10,000/день', llmRequests: '500/день', storage: '1 GB', }, }, { id: 'business', name: 'Business', price: 4990, priceMonthly: 4990, icon: Building2, color: 'text-amber-600', features: ['Всё из Pro', 'Безлимитный AI', 'Приоритетная поддержка', 'Команды', 'SLA 99.9%'], limits: { apiRequests: '100,000/день', llmRequests: '5,000/день', storage: '10 GB', }, }, ]; const mockTransactions = [ { id: '1', date: '2026-02-28', amount: 990, type: 'subscription', description: 'Подписка Pro' }, { id: '2', date: '2026-02-15', amount: 500, type: 'topup', description: 'Пополнение баланса' }, { id: '3', date: '2026-01-28', amount: 990, type: 'subscription', description: 'Подписка Pro' }, ]; export function BillingTab() { const { user } = useAuth(); const [selectedPlan, setSelectedPlan] = useState(null); const [showTopup, setShowTopup] = useState(false); const [topupAmount, setTopupAmount] = useState(''); if (!user) return null; const currentPlan = plans.find(p => p.id === user.tier) || plans[0]; const handleUpgrade = (planId: string) => { setSelectedPlan(planId); }; const handleTopup = () => { const amount = parseInt(topupAmount, 10); if (isNaN(amount) || amount < 100) return; setShowTopup(false); setTopupAmount(''); }; return (
{/* Balance Card */}

Текущий баланс

{(user.balance ?? 0).toLocaleString('ru-RU')} ₽

{showTopup && (
{[100, 500, 1000, 5000].map((amount) => ( ))}
setTopupAmount(e.target.value)} placeholder="Сумма" className="flex-1 px-3 py-2 bg-surface border border-border rounded-lg text-sm text-primary focus:outline-none focus:border-accent" />

Минимальная сумма: 100 ₽

)}
{/* Current Plan */}

{currentPlan.name}

{currentPlan.price === 0 ? 'Бесплатно' : `${currentPlan.price.toLocaleString('ru-RU')} ₽/мес`}

{user.tier !== 'business' && ( )}

API запросы

{currentPlan.limits.apiRequests}

AI запросы

{currentPlan.limits.llmRequests}

Хранилище

{currentPlan.limits.storage}

{/* Plans Comparison */} {selectedPlan && (
{plans.map((plan) => ( setSelectedPlan(plan.id)} >
{plan.name} {user.tier === plan.id && ( Текущий )}

{plan.price === 0 ? 'Бесплатно' : `${plan.price.toLocaleString('ru-RU')} ₽`} {plan.price > 0 && /мес}

    {plan.features.map((feature, idx) => (
  • {feature}
  • ))}
{user.tier !== plan.id && plan.id !== 'free' && ( )}
))}
)} {/* Payment Methods */}

Карты не добавлены

{/* Transaction History */}
{mockTransactions.length === 0 ? (

История платежей пуста

) : ( mockTransactions.map((tx) => (
{tx.type === 'topup' ? ( ) : ( )}

{tx.description}

{new Date(tx.date).toLocaleDateString('ru-RU')}

{tx.type === 'topup' ? '+' : '-'}{tx.amount.toLocaleString('ru-RU')} ₽
)) )}
); } function Section({ title, icon: Icon, children }: { title: string; icon: React.ElementType; children: React.ReactNode }) { return (

{title}

{children}
); }