"use client"; // ============================================================================ // External Channel Detail Page // ============================================================================ import React, { useEffect, useState } from "react"; import { use } from "react"; import Link from "next/link"; import { useRouter } from "next/navigation"; import { DashboardHeader } from "@/components/layout/dashboard-header"; import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from "@/components/ui/card"; import { Button } from "@/components/ui/button"; import { Badge } from "@/components/ui/badge"; import { Alert, AlertDescription } from "@/components/ui/alert"; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from "@/components/ui/table"; import { externalChannelsApi } from "@/lib/api"; import { formatNumber, formatMetric, formatCurrency, formatUsername, formatDate, formatCompactNumber, } from "@/lib/utils/format"; import { ExternalLink as ExternalLinkIcon, Users, TrendingUp, ArrowLeft, Loader2, AlertCircle, BarChart3, Pencil, Trash2, } from "lucide-react"; import type { ExternalChannelDetail } from "@/lib/types/api"; interface PageProps { params: Promise<{ id: string }>; } export default function ExternalChannelDetailPage({ params }: PageProps) { const resolvedParams = use(params); const router = useRouter(); const [channel, setChannel] = useState(null); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); useEffect(() => { const loadChannel = async () => { try { setLoading(true); const data = await externalChannelsApi.get(resolvedParams.id); setChannel(data); } catch (err: any) { setError(err?.error?.message || "Ошибка загрузки канала"); } finally { setLoading(false); } }; loadChannel(); }, [resolvedParams.id]); const handleDelete = async () => { if (!channel) return; if (!confirm(`Удалить канал "${channel.title}"?`)) return; try { await externalChannelsApi.delete(channel.id); router.push("/external-channels"); } catch (err: any) { alert(err?.error?.message || "Ошибка удаления канала"); } }; if (loading) { return ( <>
); } if (error || !channel) { return ( <>
{error || "Канал не найден"}
); } return ( <>

{channel.title}

{channel.username ? ( {formatUsername(channel.username)} ) : ( {channel.link} )} Добавлен {formatDate(channel.created_at)}
{channel.description && ( Описание

{channel.description}

)}
Подписчиков
{channel.subscribers_count ? formatCompactNumber(channel.subscribers_count) : "—"}

В канале

Всего закупов
{formatNumber(channel.total_purchases)}

В этом канале

Средний CPF
₽{formatMetric(channel.avg_cpf)}

По всем закупам

Средний CPM
₽{formatMetric(channel.avg_cpm)}

Стоимость 1000 просмотров

История закупов Все рекламные размещения в этом канале {channel.purchases.length === 0 ? (

Закупов в этом канале пока нет

) : ( Целевой канал Дата Стоимость Подписчики CPF {channel.purchases.map((purchase) => ( {purchase.target_channel.title} {formatDate( purchase.actual_date || purchase.scheduled_date )} {formatCurrency(purchase.cost)} {formatNumber(purchase.subscriptions_count)} ₽{formatMetric(purchase.cpf)} ))}
)}
); }