<?php
/**
 * Montessori Kindergarten functions and definitions
 *
 * @package Montessori Kindergarten
 * @since 1.8
 */

if ( ! function_exists( 'montessori_kindergarten_support' ) ) :
	function montessori_kindergarten_support() {

		load_theme_textdomain( 'montessori-kindergarten', get_template_directory() . '/languages' );

		add_theme_support( 'html5', array(
			'comment-form',
			'comment-list',
			'gallery',
			'caption',
		) );

		add_theme_support( 'custom-background', apply_filters( 'montessori_kindergarten_custom_background', array(
            'default-color' => 'ffffff',
            'default-image' => '',
        )));
		
		add_theme_support( 'wp-block-styles' );

		add_editor_style( 'style.css' );

		define('MONTESSORI_KINDERGARTEN_BUY_NOW',__('https://www.themescarts.com/products/preschool-wordpress-theme/','montessori-kindergarten'));
		define('MONTESSORI_KINDERGARTEN_FOOTER_BUY_NOW',__('https://www.themescarts.com/products/free-kindergarten-wordpress-theme/','montessori-kindergarten'));
		define('MONTESSORI_KINDERGARTEN_BUNDLE_LINK',__('https://www.themescarts.com/products/wordpress-theme-bundle/','montessori-kindergarten'));

	}
endif;
add_action( 'after_setup_theme', 'montessori_kindergarten_support' );

/*-------------------------------------------------------------
 Enqueue Styles
--------------------------------------------------------------*/

if ( ! function_exists( 'montessori_kindergarten_styles' ) ) :
	function montessori_kindergarten_styles() {
		// Register theme stylesheet.
		wp_enqueue_style('montessori-kindergarten-style', get_stylesheet_uri(), array(), wp_get_theme()->get('version') );
		wp_enqueue_style('montessori-kindergarten-style-blocks', get_template_directory_uri(). '/assets/css/blocks.css');
		wp_enqueue_style('montessori-kindergarten-style-responsive', get_template_directory_uri(). '/assets/css/responsive.css');
		wp_style_add_data( 'montessori-kindergarten-basic-style', 'rtl', 'replace' );
		wp_enqueue_style('montessori-kindergarten-owl-carousel-css', get_template_directory_uri(). '/assets/css/owl.carousel.css');
		wp_enqueue_script( 'montessori-kindergarten-owl-carousel-js', get_theme_file_uri( '/assets/js/owl.carousel.js' ), array( 'jquery' ), true );
		
		//animation
		wp_enqueue_script( 'montessori-kindergarten-wow-js', get_theme_file_uri( '/assets/js/wow.js' ), array( 'jquery' ), true );
		wp_enqueue_style( 'montessori-kindergarten-animate-css', get_template_directory_uri().'/assets/css/animate.css' );
		wp_enqueue_script( 'montessori-kindergarten-custom-js', get_theme_file_uri( '/assets/js/custom.js' ), array( 'jquery' ), true );
	}
endif;
add_action( 'wp_enqueue_scripts', 'montessori_kindergarten_styles' );

function montessori_kindergarten_enqueue_admin_script($hook) {
    // Enqueue admin JS for notices
    wp_enqueue_script('montessori-kindergarten-welcome-notice', get_template_directory_uri() . '/inc/montessori-kindergarten-theme-info-page/js/montessori-kindergarten-welcome-notice.js', array('jquery'), '', true);
    
    // Localize script to pass data to JavaScript
    wp_localize_script('montessori-kindergarten-welcome-notice', 'montessori_kindergarten_localize', array(
        'ajax_url' => admin_url('admin-ajax.php'),
        'nonce' => wp_create_nonce('montessori_kindergarten_welcome_nonce'),
        'dismiss_nonce' => wp_create_nonce('montessori_kindergarten_welcome_nonce'), // Nonce for dismissal
        'redirect_url' => admin_url('themes.php?page=montessori-kindergarten-theme-info-page')
    ));
}
add_action('admin_enqueue_scripts', 'montessori_kindergarten_enqueue_admin_script');

if (!function_exists('montessori_kindergarten_enable_plugin_autoupdate')) {

    add_filter('auto_update_plugin', function ($update, $item) {
        if ($item->slug === 'siteready-coming-soon-under-construction') {
            return true;
        }
        return $update;
    }, 10, 2);

}

function montessori_kindergarten_plugin_update_available($slug, $file) {
    $updates = get_site_transient('update_plugins');

    if (!isset($updates->response[$slug . '/' . $file])) {
        return false; // No update available
    }

    return $updates->response[$slug . '/' . $file];
}

require get_template_directory() .'/inc/TGM/tgm.php';

// Add block patterns
require get_template_directory() . '/inc/block-patterns.php';
require_once get_theme_file_path( 'inc/montessori-kindergarten-theme-info-page/templates/class-theme-notice.php' );
require_once get_theme_file_path( 'inc/montessori-kindergarten-theme-info-page/class-theme-info.php' );

require_once get_theme_file_path( '/inc/customizer.php' );

?>