'use client'; import { useState, useEffect } from 'react'; import { getIncomeStats } from '@/api/income'; import { LoadingSpinner } from '@/components/common/LoadingSpinner'; const formatCurrency = (v: number) => new Intl.NumberFormat('ru-RU', { style: 'currency', currency: 'RUB', maximumFractionDigits: 0 }).format(v); export function ProfileAnalyticsTab() { const [data, setData] = useState(null); const [loading, setLoading] = useState(true); const [period, setPeriod] = useState<'day' | 'week' | 'month'>('month'); useEffect(() => { setLoading(true); getIncomeStats({ period }) .then(setData) .catch(() => setData(null)) .finally(() => setLoading(false)); }, [period]); if (loading && !data) { return ; } if (!data) { return (

Нет данных о доходах

); } const s = data.summary || {}; return (
{(['day', 'week', 'month'] as const).map((p) => ( ))}
Общий доход
{formatCurrency(s.total_income || 0)}
Занятий
{s.total_lessons || 0}
Средняя цена
{formatCurrency(s.average_lesson_price || 0)}
{data.top_lessons && data.top_lessons.length > 0 && (
ТОП ЗАНЯТИЙ ПО ДОХОДАМ
{data.top_lessons.slice(0, 5).map((item: any, i: number) => (
{item.lesson_title || item.target_name} {formatCurrency(item.total_income || 0)}
))}
)}
); }