import { useState } from "preact/hooks"; import type { Place } from "../../lib/types"; import type { UserLocation } from "../../lib/use-location"; import { haversineKm, formatDistance } from "../../lib/geo"; import { CategoryBadge } from "./CategoryBadge"; import { isOpenNow } from "../../lib/open-hours"; function copyAddress(address: string, setCopied: (v: boolean) => void) { navigator.clipboard.writeText(address).then(() => { setCopied(true); setTimeout(() => setCopied(false), 1500); }); } export function PlaceCard({ place, expanded, onToggle, location, passed, next }: { place: Place; expanded?: boolean; onToggle?: () => void; location?: UserLocation | null; passed?: boolean; next?: boolean; }) { const [copied, setCopied] = useState(false); const dist = location && place.lat && place.lng ? haversineKm({ lat: location.lat, lng: location.lng }, { lat: place.lat, lng: place.lng }) : null; const open = isOpenNow(place); const closed = open === false; return (