import { useState } from "preact/hooks"; import type { Trip, SafetyData } from "../../lib/types"; import type { UserLocation } from "../../lib/use-location"; import { haversineKm, formatDistance } from "../../lib/geo"; import { PlaceCard } from "../shared/PlaceCard"; import { OfflineButton } from "../OfflineButton"; export function SafetyTab({ safety, location, trip }: { safety: SafetyData; location: UserLocation | null; trip: Trip }) { const [expandedHospital, setExpandedHospital] = useState(null); const hospitals = location ? [...safety.hospitals].sort((a, b) => { const da = haversineKm({ lat: location.lat, lng: location.lng }, { lat: a.lat, lng: a.lng }); const db = haversineKm({ lat: location.lat, lng: location.lng }, { lat: b.lat, lng: b.lng }); return da - db; }) : safety.hospitals; return (
{safety.cellCoverage && safety.cellCoverage.length > 0 && (
{safety.cellCoverage.map((seg, i) => (
{seg.segment} {seg.status === "full" ? "FULL" : seg.status === "spotty" ? "SPOTTY" : "NO SERVICE"}
))}
)} {safety.crashProtocol && safety.crashProtocol.length > 0 && (
{safety.crashProtocol.map((step, i) => (
{i + 1}
{step}
))}
)} {hospitals.length > 0 && (
{hospitals.map((h, i) => ( setExpandedHospital(expandedHospital === i ? null : i) } location={location} /> ))}
)} {safety.contacts && safety.contacts.length > 0 && (
{safety.contacts.map((c, i) => (
{c.name}
{c.notes &&
{c.notes}
} {c.phone}
))}
)} {safety.checklist && safety.checklist.length > 0 && (
    {safety.checklist.map((item, i) => (
  • {item}
  • ))}
)}
); }