'use client'; import { useState, useEffect } from 'react'; import { getReferralProfile, getReferralStats } from '@/api/referrals'; import { LoadingSpinner } from '@/components/common/LoadingSpinner'; import { useToast } from '@/contexts/ToastContext'; const formatCurrency = (v: number) => new Intl.NumberFormat('ru-RU', { style: 'currency', currency: 'RUB', maximumFractionDigits: 0 }).format(v); export function ReferralsPageContent() { const { showToast } = useToast(); const [profile, setProfile] = useState(null); const [stats, setStats] = useState(null); const [loading, setLoading] = useState(true); const [copied, setCopied] = useState(false); useEffect(() => { Promise.all([ getReferralProfile().then(setProfile), getReferralStats().then(setStats), ]) .finally(() => setLoading(false)); }, []); const copyLink = () => { if (profile?.referral_link) { navigator.clipboard.writeText(profile.referral_link); setCopied(true); showToast('Реферальная ссылка скопирована', 'success'); setTimeout(() => setCopied(false), 2000); } }; if (loading) { return ; } if (!profile) { return (

Реферальная программа недоступна

); } return (
РЕФЕРАЛЬНАЯ ССЫЛКА
{profile.referral_code && (

Код: {profile.referral_code}

)}
{stats && (
Уровень
{stats.current_level?.name || '-'}
Баллы
{stats.total_points ?? 0}
Рефералов
{stats.referrals?.total ?? 0}
Заработано
{formatCurrency(stats.earnings?.total ?? stats.bonus_account?.balance ?? 0)}
)}
); }