<?php
/**
 * Coupon Shop functions and definitions
 *
 * @link https://developer.wordpress.org/themes/basics/theme-functions/
 *
 * @subpackage Coupon Shop
 * @since Coupon Shop 1.0
 */

if ( ! function_exists( 'coupon_shop_setup' ) ) :
/**
 * Sets up theme defaults and registers support for various WordPress features.
 *
 * Note that this function is hooked into the after_setup_theme hook, which runs
 * before the init hook. The init hook is too late for some features, such as indicating
 * support post thumbnails.
 */
function coupon_shop_setup() {
	load_theme_textdomain( 'coupon-shop', get_template_directory() . '/languages' );

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

	/**
	 * Notice.
	 */
	require_once get_template_directory() . '/inc/notice/notice.php';

	/**
	 * Theme Info Page.
	 */
	require get_template_directory() . '/inc/addon.php';

	/**
	 * Customizer
	 */
	require get_template_directory() . '/inc/customizer.php';
}
endif;
add_action( 'after_setup_theme', 'coupon_shop_setup' );

function coupon_shop_block_assets(){
	wp_enqueue_style( 'coupon-shop-fontawesome', get_template_directory_uri() . '/assets/font-awesome/css/all.css', array(), '7.1.0' );
	wp_enqueue_style( 'coupon-shop-animatecss', get_template_directory_uri() . '/assets/css/animate.css');
	wp_enqueue_style( 'coupon-shop-owlcarousel-css', get_template_directory_uri() . '/assets/css/owl.carousel.css');
	wp_enqueue_style( 'coupon-shop-style', get_template_directory_uri() . '/style.css', array(), wp_get_theme()->get( 'Version' ) );
	wp_enqueue_script('coupon-shop-wow-script', get_template_directory_uri() . '/assets/js/wow.js', array('jquery'));
	wp_enqueue_script('coupon-shop-owlcarousel-js', get_template_directory_uri() . '/assets/js/owl.carousel.js', array('jquery'));
	wp_enqueue_script('coupon-shop-script', get_template_directory_uri() . '/assets/js/script.js', array('jquery'), '1.0.0', true);
	wp_style_add_data( 'coupon-shop-style', 'rtl', 'replace' );
}
add_action('enqueue_block_assets', 'coupon_shop_block_assets');

function coupon_shop_setup_theme() {
	if ( ! defined( 'COUPON_SHOP_PREMIUM_PAGE' ) ) {
		define('COUPON_SHOP_PREMIUM_PAGE',__('https://www.theclassictemplates.com/products/coupon-wordpress-theme','coupon-shop'));
	}
	if ( ! defined( 'COUPON_SHOP_PRO_NAME' ) ) {
		define( 'COUPON_SHOP_PRO_NAME', __( 'About Coupon Shop', 'coupon-shop' ));
	}
	if ( ! defined( 'COUPON_SHOP_THEME_PAGE' ) ) {
		define('COUPON_SHOP_THEME_PAGE',__('https://www.theclassictemplates.com/collections/best-wordpress-templates','coupon-shop'));
	}
	if ( ! defined( 'COUPON_SHOP_SUPPORT' ) ) {
		define('COUPON_SHOP_SUPPORT',__('https://wordpress.org/support/theme/coupon-shop/','coupon-shop'));
	}
	if ( ! defined( 'COUPON_SHOP_REVIEW' ) ) {
		define('COUPON_SHOP_REVIEW',__('https://wordpress.org/support/theme/coupon-shop/reviews/','coupon-shop'));
	}
	if ( ! defined( 'COUPON_SHOP_PRO_DEMO' ) ) {
		define('COUPON_SHOP_PRO_DEMO',__('https://live.theclassictemplates.com/coupon-shop-pro/','coupon-shop'));
	}
	if ( ! defined( 'COUPON_SHOP_THEME_DOCUMENTATION' ) ) {
		define('COUPON_SHOP_THEME_DOCUMENTATION',__('https://live.theclassictemplates.com/demo/docs/coupon-shop-free/','coupon-shop'));
	}
	if ( ! defined( 'COUPON_SHOP_BUNDLE_PAGE' ) ) {
		define('COUPON_SHOP_BUNDLE_PAGE',__('https://www.theclassictemplates.com/products/wordpress-theme-bundle','coupon-shop'));
	}
}
add_action('after_setup_theme', 'coupon_shop_setup_theme');

function coupon_shop_enqueue_admin_script($hook) {
    // Enqueue admin JS for notices
    wp_enqueue_script('coupon-shop-welcome-notice', get_template_directory_uri() . '/inc/notice/notice.js', array('jquery'), '', true);
    
    // Localize script to pass data to JavaScript
    wp_localize_script('coupon-shop-welcome-notice', 'coupon_shop_localize', array(
        'ajax_url' => admin_url('admin-ajax.php'),
        'nonce' => wp_create_nonce('coupon_shop_welcome_nonce'),
        'dismiss_nonce' => wp_create_nonce('coupon_shop_welcome_nonce'), 
        'redirect_url' => admin_url('themes.php?page=coupon-shop')
    ));
}
add_action('admin_enqueue_scripts', 'coupon_shop_enqueue_admin_script');

add_filter( 'woocommerce_enable_setup_wizard', '__return_false' );

add_action('init', function() {
    if ( get_option('__gutentor_do_redirect') ) {
        update_option('__gutentor_do_redirect', false);
    }
});