/**
 * FR-024: convert an organizer-pasted Google Maps share link into an
 * embeddable iframe src, without a Google Maps API key — the same
 * `output=embed` parameter Google's own "Embed a map" share option adds.
 * Works for standard `google.com/maps/...` links; shortened links
 * (`maps.app.goo.gl/...`) may not preserve the parameter through the
 * redirect, which is why the detail page also renders a plain "Open in
 * Google Maps" link as a fallback.
 */
export function toGoogleMapsEmbedSrc(url: string): string | null {
  try {
    const parsed = new URL(url);

    if (parsed.hostname.includes("google.") || parsed.hostname.includes("goo.gl")) {
      if (!parsed.pathname.includes("/embed")) {
        parsed.searchParams.set("output", "embed");
      }
      return parsed.toString();
    }

    return null;
  } catch {
    return null;
  }
}
