<?php
/**
 * Astra Child Theme Functions
 */

/**
 * Load parent and child theme styles.
 */
add_action( 'wp_enqueue_scripts', function() {

    wp_enqueue_style(
        'astra-parent',
        get_template_directory_uri() . '/style.css'
    );

    wp_enqueue_style(
        'astra-child',
        get_stylesheet_uri(),
        array( 'astra-parent' ),
        wp_get_theme()->get( 'Version' )
    );

} );

/**
 * Load Google Fonts (Montserrat + DM Sans), the Web Guidance global
 * stylesheet, and the Web Guidance global JavaScript.
 *
 * Front end only (never on wp-admin). main.css/main.js are versioned
 * with filemtime() so browsers pick up changes immediately without
 * manual cache-busting.
 */
add_action( 'wp_enqueue_scripts', function() {

    if ( is_admin() ) {
        return;
    }

    wp_enqueue_style(
        'webguidance-fonts',
        'https://fonts.googleapis.com/css2?family=Montserrat:wght@700;800;900&family=DM+Sans:opsz,wght@9..40,400;9..40,500;9..40,600&display=swap',
        array(),
        null
    );

    $css_rel_path = '/assets/css/main.css';
    $js_rel_path  = '/assets/js/main.js';

    $css_full_path = get_stylesheet_directory() . $css_rel_path;
    $js_full_path  = get_stylesheet_directory() . $js_rel_path;

    if ( file_exists( $css_full_path ) ) {
        wp_enqueue_style(
            'webguidance-global',
            get_stylesheet_directory_uri() . $css_rel_path,
            array( 'astra-child', 'webguidance-fonts' ),
            filemtime( $css_full_path )
        );
    }

    if ( file_exists( $js_full_path ) ) {
        wp_enqueue_script(
            'webguidance-global',
            get_stylesheet_directory_uri() . $js_rel_path,
            array(),
            filemtime( $js_full_path ),
            true // load in footer
        );
    }

} );

/**
 * Disable Astra Global Colors inside Elementor.
 */
add_filter(
    'astra_disable_global_colors_in_elementor',
    '__return_true'
);