"use client"; import { useEffect } from "react"; import { createPortal } from "react-dom"; import Image from "next/image"; import { X, Calendar, ExternalLink } from "lucide-react"; import type { NewsItem } from "@/types/content"; interface NewsModalProps { item: NewsItem | null; onClose: () => void; } function formatDate(iso: string): string { try { const d = new Date(iso); const date = d.toLocaleDateString("ru-RU", { day: "numeric", month: "long", year: "numeric", }); if (iso.includes("T")) { const time = d.toLocaleTimeString("ru-RU", { hour: "2-digit", minute: "2-digit" }); return `${date}, ${time}`; } return date; } catch { return iso; } } export function NewsModal({ item, onClose }: NewsModalProps) { useEffect(() => { if (!item) return; function onKey(e: KeyboardEvent) { if (e.key === "Escape") onClose(); } document.addEventListener("keydown", onKey); return () => document.removeEventListener("keydown", onKey); }, [item, onClose]); useEffect(() => { if (item) { const scrollbarWidth = window.innerWidth - document.documentElement.clientWidth; document.body.style.overflow = "hidden"; document.body.style.paddingRight = `${scrollbarWidth}px`; } else { document.body.style.overflow = ""; document.body.style.paddingRight = ""; } return () => { document.body.style.overflow = ""; document.body.style.paddingRight = ""; }; }, [item]); if (!item) return null; return createPortal(