<?php
/**
* Enqueue scripts and styles
*
* @package GridLane WordPress Theme
* @copyright Copyright (C) 2025 ThemesDNA
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 or later
* @author ThemesDNA <themesdna@gmail.com>
*/

function gridlane_scripts() {
    wp_enqueue_style('gridlane-maincss', get_stylesheet_uri(), array(), null);
    wp_enqueue_style('fontawesome', get_template_directory_uri() . '/assets/css/all.min.css', array(), null );
    wp_enqueue_style('gridlane-webfont', '//fonts.googleapis.com/css?family=Poppins:400,400i,500,500i,700,700i&amp;display=swap', array(), null);

    $gridlane_fitvids_active = false;
    if ( gridlane_is_fitvids_active() ) {
        $gridlane_fitvids_active = true;
    }
    if ( $gridlane_fitvids_active ) {
        wp_enqueue_script('fitvids', get_template_directory_uri() .'/assets/js/jquery.fitvids.min.js', array( 'jquery' ), null, true);
    }

    $gridlane_backtotop_active = false;
    if ( gridlane_is_backtotop_active() ) {
        $gridlane_backtotop_active = true;
    }

    $gridlane_primary_menu_active = false;
    if ( gridlane_is_primary_menu_active() ) {
        $gridlane_primary_menu_active = true;
    }
    $gridlane_secondary_menu_active = false;
    if ( gridlane_is_secondary_menu_active() ) {
        $gridlane_secondary_menu_active = true;
    }

    $gridlane_sticky_header_active = false;
    $gridlane_sticky_header_mobile_active = false;
    if ( gridlane_is_sticky_header_active() ) {
        $gridlane_sticky_header_active = true;
    }
    if ( gridlane_is_sticky_mobile_header_active() ) {
        $gridlane_sticky_header_mobile_active = true;
    }

    $gridlane_sticky_sidebar_active = true;
    if ( is_page_template( array( 'template-full-width-page.php', 'template-full-width-post.php' ) ) ) {
       $gridlane_sticky_sidebar_active = false;
    }
    if ( is_404() ) {
        $gridlane_sticky_sidebar_active = false;
    }
    if ( $gridlane_sticky_sidebar_active ) {
        wp_enqueue_script('ResizeSensor', get_template_directory_uri() .'/assets/js/ResizeSensor.min.js', array( 'jquery' ), null, true);
        wp_enqueue_script('theia-sticky-sidebar', get_template_directory_uri() .'/assets/js/theia-sticky-sidebar.min.js', array( 'jquery' ), null, true);
    }

    wp_enqueue_script('gridlane-navigation', get_template_directory_uri() . '/assets/js/navigation.js', array(), null, true );
    wp_enqueue_script('gridlane-skip-link-focus-fix', get_template_directory_uri() . '/assets/js/skip-link-focus-fix.js', array(), null, true );
    wp_enqueue_script('gridlane-customjs', get_template_directory_uri() .'/assets/js/custom.js', array( 'jquery', 'imagesloaded' ), null, true);

    wp_localize_script( 'gridlane-customjs', 'gridlane_ajax_object',
        array(
            'ajaxurl' => esc_url_raw( admin_url( 'admin-ajax.php' ) ),
            'primary_menu_active' => $gridlane_primary_menu_active,
            'secondary_menu_active' => $gridlane_secondary_menu_active,
            'sticky_header_active' => $gridlane_sticky_header_active,
            'sticky_header_mobile_active' => $gridlane_sticky_header_mobile_active,
            'sticky_sidebar_active' => $gridlane_sticky_sidebar_active,
            'fitvids_active' => $gridlane_fitvids_active,
            'backtotop_active' => $gridlane_backtotop_active,
        )
    );

    if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
        wp_enqueue_script( 'comment-reply' );
    }
}
add_action( 'wp_enqueue_scripts', 'gridlane_scripts' );

/**
 * Enqueue styles for the block-based editor.
 */
function gridlane_block_editor_styles() {
    wp_enqueue_style( 'gridlane-block-editor-style', get_template_directory_uri() . '/assets/css/editor-blocks.css', array(), null );
}
add_action( 'enqueue_block_editor_assets', 'gridlane_block_editor_styles' );

/**
 * Enqueue customizer styles.
 */
function gridlane_enqueue_customizer_styles() {
    wp_enqueue_style( 'gridlane-customizer-styles', get_template_directory_uri() . '/inc/admin/css/customizer-style.css', array(), null );
    wp_enqueue_style('fontawesome', get_template_directory_uri() . '/assets/css/all.min.css', array(), null );
}
add_action( 'customize_controls_enqueue_scripts', 'gridlane_enqueue_customizer_styles' );