(g => { var h, a, k, p = "The Google Maps JavaScript API", c = "google", l = "importLibrary", q = "__ib__", m = document, b = window; b = b[c] || (b[c] = {}); var d = b.maps || (b.maps = {}), r = new Set, e = new URLSearchParams, u = () => h || (h = new Promise(async (f, n) => { await (a = m.createElement("script")); e.set("libraries", [...r] + ""); for (k in g) e.set(k.replace(/[A-Z]/g, t => "_" + t[0].toLowerCase()), g[k]); e.set("callback", c + ".maps." + q); a.src = `https://maps.${c}apis.com/maps/api/js?` + e; d[q] = f; a.onerror = () => h = n(Error(p + " could not load.")); a.nonce = m.querySelector("script[nonce]")?.nonce || ""; m.head.append(a) })); d[l] ? console.warn(p + " only loads once. Ignoring:", g) : d[l] = (f, ...n) => r.add(f) && u().then(() => d[l](f, ...n)) })({
    key: "AIzaSyD3yVUVUNhQFj2cAVzL7XkZ1_5aK-iGsKc",
    v: "weekly",
});

let map;

async function initMap(localita) {
    const areaMap = document.querySelector('.area-map');
    areaMap.classList.remove('hidden')

    const { Map } = await google.maps.importLibrary("maps");
    const { AdvancedMarkerElement, PinElement } = await google.maps.importLibrary(
        "marker",
    );

    const geocoder = new google.maps.Geocoder();

    geocoder.geocode({ 'address': localita }, function (results, status) {
        if (status === 'OK') {
            const centro = results[0].geometry.location;

            const map = new google.maps.Map(document.getElementById("map"), {
                zoom: 13,
                center: centro,
                mapId: "DEMO_MAP_ID",
            });

            const marker = new google.maps.marker.AdvancedMarkerElement({
                map,
                position: centro
            });

            const contentString =
                '<div>' +
                '<img src="https://artigian.casa/lp/img-share/logo.svg" alt="Logo Artigian Casa">' +
                '<h3>Interveniamo a ' + localita + '</h3>' +
                ' <p>Chiama: <a href="tel:3208720485">320 8720 485</a></p>' +
                "</div>";

            const infowindow = new google.maps.InfoWindow({
                content: contentString,
                ariaLabel: "Artigian Casa",
            });

            infowindow.open(map, marker);

            marker.addListener("click", () => {
                infowindow.open({
                    anchor: marker,
                    map,
                });
            });

        } else {
            console.log('Nessun risultato per la località: ' + status);
        }
    });
}
var localita = "<?php echo $localita; ?>";