import { getNip52CalendarEventTagExtras, 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 { Button } from '@/components/ui/button' import { Calendar, ExternalLink, Link2, MapPin } from 'lucide-react' 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]) 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 return (
{hasLocations ? (
{meta.locations.length > 1 ? t('calendarNip52Locations') : t('calendarNip52Location')}
{meta.locations.length === 1 ? (

{meta.locations[0]}

) : ( )}
) : null} {summaryTrim ? (
{t('calendarNip52Summary')}
{summaryTrim}
) : null} {hasGeo ? (
{t('calendarNip52Geohash')}

{meta.geo.trim()}

) : null}
) } const hasDayD = !isDateBased && extras.dayGranularities.length > 0 const hasInclusions = extras.calendarInclusions.length > 0 const hasR = extras.rTags.length > 0 const hasD = !!meta.d?.trim() const hasUnknown = extras.unknownTags.length > 0 if (!hasDayD && !hasInclusions && !hasR && !hasD && !hasUnknown) return null return (
{hasDayD ? (
{t('calendarNip52DayIndices')}
{extras.dayGranularities.map((d) => ( D={d} ))}
) : null} {hasInclusions ? (
{t('calendarNip52CalendarInclusion')}

{t('calendarNip52CalendarInclusionHint')}

) : null} {hasR ? (
{t('calendarNip52References')}
) : null} {hasD ? (
{t('calendarNip52Identifier')}

{meta.d.trim()}

) : null} {hasUnknown ? (
{t('calendarNip52OtherTags')}
{extras.unknownTags.map((tag, idx) => (
{tag[0] || '—'}
{tag.length > 1 ? tag.slice(1).join(' · ') : '—'}
))}
) : null}
) }