<?php

/** Only accept a Google Maps iframe source, never a share/short URL. */
function is_valid_google_map_embed_url(?string $url): bool
{
    if (!is_string($url) || $url === '' || !filter_var($url, FILTER_VALIDATE_URL)) {
        return false;
    }

    $parts = parse_url($url);
    $host = strtolower((string) ($parts['host'] ?? ''));
    $path = (string) ($parts['path'] ?? '');

    return ($parts['scheme'] ?? '') === 'https'
        && in_array($host, ['www.google.com', 'google.com'], true)
        && (str_starts_with($path, '/maps/embed') || str_starts_with($path, '/maps/embed/v1/'));
}
