/* global React */
// ────────────────────────────────────────────────────────────
// EVENT DETAIL — детали одного события
// ────────────────────────────────────────────────────────────
window.EventDetailScreen = ({ T, dark, ev, onBack, onShowTsunami }) => {
const mapRef = React.useRef(null);
const mapId = React.useMemo(() => "map-detail-" + Math.random().toString(36).slice(2,8), []);
React.useEffect(() => {
if (!window.L || !ev) return;
if (mapRef.current) { mapRef.current.remove(); mapRef.current = null; }
const m = window.L.map(mapId, {
zoomControl: false, attributionControl: false,
}).setView([ev.lat, ev.lon], 5);
const tileUrl = dark
? "https://{s}.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}{r}.png"
: "https://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}{r}.png";
window.L.tileLayer(tileUrl, { maxZoom: 10 }).addTo(m);
const color = window.magColor(ev.mag, T);
const r = 8 + (ev.mag - 4) * 5;
window.L.circleMarker([ev.lat, ev.lon], {
radius: r, color, fillColor: color, fillOpacity: 0.35, weight: 2,
}).addTo(m);
window.L.circleMarker([ev.lat, ev.lon], {
radius: 3, color: "#fff", fillColor: color, fillOpacity: 1, weight: 2,
}).addTo(m);
mapRef.current = m;
return () => { if (mapRef.current) { mapRef.current.remove(); mapRef.current = null; } };
}, [dark, ev]);
if (!ev) return null;
const usgsUrl = ev.id && /^[a-z0-9]+$/i.test(String(ev.id))
? `https://earthquake.usgs.gov/earthquakes/eventpage/${ev.id}`
: null;
return (
{window.magLabel(ev.mag).toUpperCase()}
{ev.place}
{ev.flag} {ev.region}
{/* Сейсмограф */}
ВОЛНОВАЯ ФОРМА · ИЛЛЮСТРАТИВНО
{/* Параметры */}
= 0 ? "N" : "S"}`} />
= 0 ? "E" : "W"}`} />
{ev.confirmed && (
✓ Событие подтверждено двумя независимыми источниками
)}
{/* Tsunami warning notice for qualifying events (M >= 6.5, h <= 50, oceanic). */}
{window.TsunamiNotice && (
)}
{/* Aftershocks timeline — appears for M >= 5 if ≥ 2 aftershocks found. */}
{ev.mag >= 5.0 && window.AftershockSection && (
)}
share(ev)}>Поделиться
{usgsUrl && (
window.open(usgsUrl, "_blank")}>Открыть в USGS
)}
);
};
const Row = ({ T, k, v, last }) => (
{k}
{v}
);
const Btn = ({ T, primary, children, onClick }) => (
);
// Unified date-time formatter: "21:38:53 04 мая 2026"
function fmtFull(iso, tz) {
const months = [
"января", "февраля", "марта", "апреля", "мая", "июня",
"июля", "августа", "сентября", "октября", "ноября", "декабря",
];
const fmt = new Intl.DateTimeFormat("en-GB", {
timeZone: tz,
year: "numeric", month: "numeric", day: "2-digit",
hour: "2-digit", minute: "2-digit", second: "2-digit", hour12: false,
});
const parts = fmt.formatToParts(new Date(iso));
const get = (t) => parts.find((p) => p.type === t)?.value || "";
const day = get("day"), month = get("month"), year = get("year");
const h = get("hour"), m = get("minute"), s = get("second");
return `${h}:${m}:${s} ${day} ${months[parseInt(month, 10) - 1] || ""} ${year}`;
}
// Share — copy a one-line summary to the clipboard with a small confirmation.
// Native navigator.share on Windows surfaces only Outlook/Teams/Mail (no
// Telegram), so a clipboard copy is the most reliable cross-platform path.
function share(ev) {
const text =
`M ${ev.mag.toFixed(1)} · ${ev.place}\n` +
`${ev.timeMsk} МСК · h=${ev.depth.toFixed(1)} км · ${ev.lat.toFixed(2)}°N, ${ev.lon.toFixed(2)}°E`;
// Inside Telegram clients prefer the native "share with chat" sheet.
const tg = window.Telegram?.WebApp;
if (tg?.shareMessage) {
try { tg.shareMessage(text); return; } catch (e) {}
}
// Outside Telegram (or older clients) — copy + brief tooltip-style hint.
try {
navigator.clipboard.writeText(text).then(() => {
const node = document.createElement("div");
node.textContent = "Скопировано в буфер";
node.style.cssText =
"position:fixed;bottom:20px;left:50%;transform:translateX(-50%);" +
"background:#1B1A17;color:#F4F1EA;padding:10px 18px;border-radius:20px;" +
"font:500 13px Manrope,sans-serif;z-index:9999;box-shadow:0 4px 12px rgba(0,0,0,0.2);";
document.body.appendChild(node);
setTimeout(() => node.remove(), 2000);
});
} catch (e) {
// Last-resort fallback.
if (navigator.share) navigator.share({ text }).catch(() => {});
}
}