import { useEffect, useRef, useState } from "react"; import { useTranslation } from "react-i18next"; import CloseIcon from "../icons/CloseIcon"; /** * Полноэкранный просмотр фото сообщения: стрелки/точки на десктопе, свайп на * телефоне, Esc и клик по фону — закрыть. */ export default function ChatPhotoViewer({ photos, startIndex = 0, onClose }) { const { t } = useTranslation(); const [index, setIndex] = useState(startIndex); const touchStartRef = useRef(null); const count = photos.length; const go = (step) => setIndex((i) => (i + step + count) % count); useEffect(() => { const onKey = (e) => { if (e.key === "Escape") onClose(); else if (e.key === "ArrowRight" && count > 1) setIndex((i) => (i + 1) % count); else if (e.key === "ArrowLeft" && count > 1) setIndex((i) => (i - 1 + count) % count); }; window.addEventListener("keydown", onKey); return () => window.removeEventListener("keydown", onKey); }, [count, onClose]); if (!count) return null; const photo = photos[Math.min(index, count - 1)]; return (