'use client'; import { useState } from 'react'; import Link from 'next/link'; import { ArrowLeft, Clock, Image as ImageIcon, Copy, Check, Search } from 'lucide-react'; function timeAgo(dateStr) { if (!dateStr) return ''; const diff = Date.now() - new Date(dateStr).getTime(); const m = Math.floor(diff / 60000); if (m < 60) return `${m} мин назад`; const h = Math.floor(m / 60); if (h < 24) return `${h} ч назад`; const d = Math.floor(h / 24); if (d < 30) return `${d} дн назад`; return new Date(dateStr).toLocaleDateString('ru-RU', { day: 'numeric', month: 'short', year: 'numeric' }); } function PostCard({ p }) { const [copied, setCopied] = useState(false); const [expanded, setExpanded] = useState(false); const preview = p.content?.slice(0, 200) || ''; const isLong = (p.content?.length || 0) > 200; function copy() { navigator.clipboard.writeText(p.content || ''); setCopied(true); setTimeout(() => setCopied(false), 2000); } return (
{/* Шапка */}
{timeAgo(p.published_at || p.updated_at || p.created_at)}
{/* Картинка */} {p.image_url && ( )} {!p.image_url && (
Без изображения
)} {/* Текст */}
{expanded ? p.content : preview} {isLong && !expanded && }
{isLong && ( )}
); } export default function ChannelHistory({ channel, posts }) { const [query, setQuery] = useState(''); const filtered = query.trim() ? posts.filter(p => p.content?.toLowerCase().includes(query.toLowerCase())) : posts; return (
{/* Навигация */}
{channel.name} / История публикаций
{/* Статистика + поиск */}

{posts.length === 0 ? 'Публикаций пока нет' : `${posts.length} ${posts.length === 1 ? 'публикация' : posts.length < 5 ? 'публикации' : 'публикаций'}`}

{posts.length > 0 && (
setQuery(e.target.value)} className="pl-8 pr-3 py-1.5 text-sm border border-gray-200 dark:border-gray-700 rounded-lg bg-white dark:bg-gray-900 text-gray-800 dark:text-gray-200 placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-indigo-300 w-48" />
)}
{/* Список постов */} {filtered.length === 0 && query ? (

Ничего не найдено

) : filtered.length === 0 ? (

Опубликованных постов пока нет

Создать первый пост →
) : (
{filtered.map(p => )}
)}
); }