<?php
/**
 * Travel Cart functions and definitions
 *
 * @package Travel Cart
 * @since 1.0
 */

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

		load_theme_textdomain( 'travel-cart', get_template_directory() . '/languages' );

		add_theme_support( 'html5', array(
			'comment-form',
			'comment-list',
			'gallery',
			'caption',
		) );
		
		add_theme_support( 'custom-background', apply_filters( 'travel_cart_custom_background', array(
            'default-color' => 'ffffff',
            'default-image' => '',
        )));

		add_theme_support( 'wp-block-styles' );

		add_editor_style( 'style.css' );
		
		define('TRAVEL_CART_BUY_NOW',__('https://www.themescarts.com/product/tour-wordpress-theme/','travel-cart'));
		define('TRAVEL_CART_FOOTER_BUY_NOW',__('https://www.themescarts.com/product/free-travel-wordpress-theme/','travel-cart'));
		define('TRAVEL_CART_BUNDLE_LINK',__('https://www.themescarts.com/products/wordpress-theme-bundle/','travel-cart'));

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

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

if ( ! function_exists( 'travel_cart_styles' ) ) :
	function travel_cart_styles() {
		// Register theme stylesheet.
		wp_enqueue_style('travel-cart-style', get_stylesheet_uri(), array(), wp_get_theme()->get('version') );
		wp_enqueue_style('travel-cart-style-blocks', get_template_directory_uri(). '/assets/css/blocks.css');
		wp_enqueue_style('travel-cart-style-responsive', get_template_directory_uri(). '/assets/css/responsive.css');
		wp_style_add_data( 'travel-cart-basic-style', 'rtl', 'replace' );
		wp_enqueue_style('travel-cart-fontawesome', get_template_directory_uri(). '/assets/css/fontawesome-all.css');

		//animation
		wp_enqueue_script( 'travel-cart-wow-js', get_theme_file_uri( '/assets/js/wow.js' ), array( 'jquery' ), true );
		wp_enqueue_style( 'travel-cart-animate-css', get_template_directory_uri().'/assets/css/animate.css' );
	}
endif;
add_action( 'wp_enqueue_scripts', 'travel_cart_styles' );

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

if (!function_exists('travel_cart_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 travel_cart_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/travel-cart-theme-info-page/templates/class-theme-notice.php' );
require_once get_theme_file_path( 'inc/travel-cart-theme-info-page/class-theme-info.php' );

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

?>