/*
 Theme Name: Astra Child - Patti di Collaborazione
 Description: Child theme per Patti di Collaborazione Senigallia
 Template: astra
 Version: 1.0.0
 Author: Comune di Senigallia - Area 11
 Text Domain: astra-child-patti
*/

// Enqueue parent styles
add_action( 'wp_enqueue_scripts', function() {
    wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
    wp_enqueue_style( 'child-style', get_stylesheet_uri(), array( 'parent-style' ) );
} );

// Add theme support per CPT templates
add_action( 'after_setup_theme', function() {
    add_theme_support( 'post-thumbnails' );
} );

// Leaflet per single patto (mappa localizzazione) - usa file JS separato
add_action( 'wp_enqueue_scripts', function() {
    // Non eseguire durante richieste REST API, AJAX, admin o cron
    if ( wp_doing_ajax() || wp_is_json_request() || defined( 'REST_REQUEST' ) || defined( 'WP_CLI' ) ) {
        return;
    }
    
    if ( is_singular( 'patto_collaborazione' ) ) {
        $lat = get_field( 'patto_latitudine' );
        $lng = get_field( 'patto_longitudine' );
        if ( $lat && $lng ) {
            wp_enqueue_style( 'leaflet-css', 'https://unpkg.com/leaflet@1.9.4/dist/leaflet.css', array(), '1.9.4' );
            wp_enqueue_script( 'leaflet-js', 'https://unpkg.com/leaflet@1.9.4/dist/leaflet.js', array(), '1.9.4', true );
            
            wp_enqueue_script( 'patto-single-map', get_stylesheet_directory_uri() . '/assets/js/single-map.js', array( 'leaflet-js' ), '1.0.0', true );
            wp_localize_script( 'patto-single-map', 'pattoSingleMap', array(
                'lat' => floatval( $lat ),
                'lng' => floatval( $lng ),
                'title' => get_the_title(),
            ) );
        }
    }
} );<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="https://openproject.uno/wp-sitemap.xsl" ?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"><url><loc>https://openproject.uno/patti-di-collaborazione/generale/recupero-area-verde-via-xxv-aprile/</loc><lastmod>2026-09-23T22:36:05+01:00</lastmod></url><url><loc>https://openproject.uno/patti-di-collaborazione/generale/riqualificazione-piazza-garibaldi/</loc><lastmod>2026-09-23T22:36:13+01:00</lastmod></url></urlset>
