export async function extractCoordsFromRedirectUrl(url: string): Promise<{ latitude: string; longitude: string } | null> {
  try {
    const response = await fetch(url, { redirect: 'manual' })
    if (response.status === 301 || response.status === 302) {
      const redirectUrl = response.headers.get('location')
      if (redirectUrl) {
        const coordsMatch = redirectUrl.match(/!3d([-\d.]+)!4d([-\d.]+)/)
        if (coordsMatch) {
          return {
            latitude: coordsMatch[1],
            longitude: coordsMatch[2],
          }
        }
      }
    }
    return null
  } catch {
    return null
  }
}
