import { getNip52CalendarEventTagExtras, summarizeNip52DayGranularityTags, type CalendarEventMeta } from '@/lib/calendar-event' import { useSmartNoteNavigation } from '@/PageManager' import { Event } from 'nostr-tools' import { useMemo } from 'react' import { useTranslation } from 'react-i18next' import { Calendar, ExternalLink, Link2, MapPin } from 'lucide-react' import { cn } from '@/lib/utils' type Placement = 'beforeDescription' | 'afterDescription' /** [Geohash Explorer](https://geohash.softeng.co/) style URL for a geohash string. */ function nip52GeohashSoftengUrl(geohash: string): string { const h = geohash.trim() return `https://geohash.softeng.co/${encodeURIComponent(h)}` } /** Google Maps “place” style URL from a free-text address or place name. */ function googleMapsPlaceUrl(placeQuery: string): string { const q = placeQuery.trim() if (!q) return '#' return `https://www.google.com/maps/place/${encodeURIComponent(q).replace(/%20/g, '+')}` } export function CalendarEventNip52StructuredMeta({ placement, event, meta, isDateBased }: { placement: Placement event: Event meta: CalendarEventMeta isDateBased: boolean }) { const { t } = useTranslation() const { navigateToNote } = useSmartNoteNavigation() const extras = useMemo(() => getNip52CalendarEventTagExtras(event), [event]) const dayGranularitySummary = useMemo( () => summarizeNip52DayGranularityTags(extras.dayGranularities), [extras.dayGranularities] ) if (placement === 'beforeDescription') { const summaryTrim = meta.summary?.trim() ?? '' const hasLocations = meta.locations.length > 0 const hasGeo = !!meta.geo?.trim() if (!hasLocations && !summaryTrim && !hasGeo) return null const linkClass = 'inline-flex shrink-0 items-center gap-1 text-xs font-medium text-primary underline-offset-2 hover:text-foreground hover:underline transition-colors' return (
{summaryTrim}
{dayGranularitySummary}
{t('calendarNip52DayIndicesHint')}
{t('calendarNip52CalendarInclusionHint')}