import { useState, useEffect } from 'react' import { adminApi } from '@/api' import type { AdminMarathon } from '@/types' import { useToast } from '@/store/toast' import { NeonButton } from '@/components/ui' import { Send, Users, Trophy, AlertTriangle } from 'lucide-react' export function AdminBroadcastPage() { const [message, setMessage] = useState('') const [targetType, setTargetType] = useState<'all' | 'marathon'>('all') const [marathonId, setMarathonId] = useState(null) const [marathons, setMarathons] = useState([]) const [sending, setSending] = useState(false) const [loadingMarathons, setLoadingMarathons] = useState(false) const toast = useToast() useEffect(() => { if (targetType === 'marathon') { loadMarathons() } }, [targetType]) const loadMarathons = async () => { setLoadingMarathons(true) try { const data = await adminApi.listMarathons(0, 100) setMarathons(data.filter(m => m.status === 'active')) } catch (err) { console.error('Failed to load marathons:', err) } finally { setLoadingMarathons(false) } } const handleSend = async () => { if (!message.trim()) { toast.error('Введите сообщение') return } if (targetType === 'marathon' && !marathonId) { toast.error('Выберите марафон') return } setSending(true) try { let result if (targetType === 'all') { result = await adminApi.broadcastToAll(message) } else { result = await adminApi.broadcastToMarathon(marathonId!, message) } toast.success(`Отправлено ${result.sent_count} из ${result.total_count} сообщений`) setMessage('') } catch (err) { console.error('Failed to send broadcast:', err) toast.error('Ошибка отправки') } finally { setSending(false) } } return (
{/* Header */}

Рассылка уведомлений

{/* Target Selection */}
{/* Marathon Selection */} {targetType === 'marathon' && (
{loadingMarathons ? (
) : ( )} {marathons.length === 0 && !loadingMarathons && (

Нет активных марафонов

)}
)} {/* Message */}