/*
 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-index.xsl" ?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"><sitemap><loc>https://openproject.uno/wp-sitemap-posts-post-1.xml</loc></sitemap><sitemap><loc>https://openproject.uno/wp-sitemap-posts-page-1.xml</loc></sitemap><sitemap><loc>https://openproject.uno/wp-sitemap-posts-patto_collaborazione-1.xml</loc></sitemap><sitemap><loc>https://openproject.uno/wp-sitemap-taxonomies-category-1.xml</loc></sitemap><sitemap><loc>https://openproject.uno/wp-sitemap-taxonomies-patto_stato-1.xml</loc></sitemap><sitemap><loc>https://openproject.uno/wp-sitemap-users-1.xml</loc></sitemap></sitemapindex>
