<?php
/**
 * Pixel Watch Center functions and definitions
 *
 * @package pixel_watch_center
 * @since 1.0
 */

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

		load_theme_textdomain( 'pixel-watch-center', get_template_directory() . '/languages' );

		add_theme_support( 'custom-background', apply_filters( 'pixel_watch_center_custom_background', array(
            'default-color' => 'ffffff',
            'default-image' => '',
        )));

		// Add support for block styles.
		add_theme_support( 'wp-block-styles' );

		add_theme_support('woocommerce');

		// Enqueue editor styles.
		add_editor_style(get_stylesheet_directory_uri() . '/assets/css/editor-style.css');

		define('PIXEL_WATCH_CENTER_FREE_BUY_NOW',__('https://www.themepixels.net/products/pixel-watch-center/','pixel-watch-center'));
		define('PIXEL_WATCH_CENTER_BUY_NOW',__('https://www.themepixels.net/products/watch-center-wordpress-theme/','pixel-watch-center'));
		define('PIXEL_WATCH_CENTER_LIVE_DEMO',__('https://themepixels.net/demo-site/pixel-watch-center/','pixel-watch-center'));
		define('PIXEL_WATCH_CENTER_FREE_DOC',__('https://www.themepixels.net/docs/pixel-watch-center-free/','pixel-watch-center'));
		define('PIXEL_WATCH_CENTER_BUNDLE',__('https://www.themepixels.net/products/wp-theme-bundle','pixel-watch-center'));
		define('PIXEL_WATCH_CENTER_THEME_SUPPORT',__('https://wordpress.org/support/theme/pixel-watch-center','pixel-watch-center'));
		define('PIXEL_WATCH_CENTER_COLLECTIONS',__('https://www.themepixels.net/premium-wordpress-themes','pixel-watch-center'));
    	require_once get_theme_file_path( '/inc/customizer.php' );
	}
endif;

add_action( 'after_setup_theme', 'pixel_watch_center_support' );

if ( ! function_exists( 'pixel_watch_center_styles' ) ) :
	function pixel_watch_center_styles() {
		// Register theme stylesheet.
		$pixel_watch_center_theme_version = wp_get_theme()->get( 'Version' );

		$pixel_watch_center_version_string = is_string( $pixel_watch_center_theme_version ) ? $pixel_watch_center_theme_version : false;
		wp_enqueue_style(
			'pixel-watch-center-style',
			get_template_directory_uri() . '/style.css',
			array(),
			$pixel_watch_center_version_string
		);

		wp_style_add_data('pixel-watch-center', 'rtl', 'replace');

		wp_enqueue_style( 'dashicons' );

		wp_enqueue_style( 'animate-css', esc_url(get_template_directory_uri()).'/assets/css/animate.css' );

		wp_enqueue_style( 'owl.carousel-css', esc_url(get_template_directory_uri()).'/assets/css/owl.carousel.css' );

		wp_enqueue_script( 'jquery-wow', esc_url(get_template_directory_uri()) . '/assets/js/wow.js', array('jquery') );
        
        // Theme fonts ( Epilogue )
        wp_enqueue_style( 'pixel-watch-center-fonts', get_template_directory_uri() . '/assets/css/fonts.css', array(), $pixel_watch_center_version_string );
	    wp_enqueue_script( 'owl.carousel-js', get_template_directory_uri(). '/assets/js/owl.carousel.js', array('jquery') ,'',true);
	    
	    wp_enqueue_script( 'pixel-watch-center-custom-scripts', get_template_directory_uri() . '/assets/js/custom-script.js', array('jquery'),'' ,true );

		 //font-awesome
		 wp_enqueue_style( 'fontawesome', get_template_directory_uri() . '/inc/fontawesome/css/all.css'
		 	, array(), '6.7.0' );
	}
endif;

add_action( 'wp_enqueue_scripts', 'pixel_watch_center_styles' );


// Add block patterns
require get_template_directory() . '/inc/block-patterns.php';

// Add block styles
require get_template_directory() . '/inc/block-styles.php';

// Block Filters
require get_template_directory() . '/inc/block-filters.php';

// Svg icons
require get_template_directory() . '/inc/icon-function.php';

/**
* GET START.
*/
require get_template_directory() . '/themeinfo/pixel_watch_center_themeinfo_page.php';

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

// Force YITH Wishlist icon to show on WooCommerce product blocks
  add_filter( 'render_block', function( $pixel_watch_center_content, $pixel_watch_center_block ) {
      if ( isset( $pixel_watch_center_block['blockName'] ) && $pixel_watch_center_block['blockName'] === 'woocommerce/product-image' ) {
  
          // Add wishlist button only if plugin is active
          if ( function_exists( 'YITH_WCWL' ) ) {
              $pixel_watch_center_wishlist_button = do_shortcode('[yith_wcwl_add_to_wishlist]');
              // Add button overlay
              $pixel_watch_center_content .= '<div class="yith-wishlist-block-overlay">' . $pixel_watch_center_wishlist_button . '</div>';
          }
      }
      return $pixel_watch_center_content;
  }, 10, 2 );

// NOTICE FUNCTION
function pixel_watch_center_activation_notice() {
    if (get_option('pixel_watch_center_notice_dismissed')) {
        return;
    }

    if (isset($_GET['page']) && $_GET['page'] === 'pixel-watch-center-themeinfo-page') {
        return;
    }
    ?>
    <div class="updated notice notice-theme-info-class is-dismissible" data-notice="theme_info">
        <div class="pixel-watch-center-theme-info-notice clearfix">
            <div class="pixel-watch-center-theme-notice-content">
				<div class="notice-content">
					<div class="inner-notice-contetn">
						<h4 class="best-value"><?php esc_html_e( 'Best Value', 'pixel-watch-center' ); ?></h4>
						<h2 class="pixel-watch-center-notice-h2">
							<?php
							printf(
								/* translators: 1: Theme name */
								esc_html__('Get 30+ Premium WordPress Themes in One Bundle', 'pixel-watch-center'), '<strong>' . esc_html(wp_get_theme()->get('Name')) . '</strong>'
							);
							?>
						</h2>

						<p class="pixel-watch-center-notice-p">
							<?php
							printf(
								/* translators: 1: Theme name */
								esc_html__('Premium WordPress Themes for Business, Ecommerce, Blogs, Portfolio and more. Our themes are light & easy to customize ', 'pixel-watch-center'), '<strong>' . esc_html(wp_get_theme()->get('Name')) . '</strong>'
							);
							?>
						</p>
					</div>
					<div class="inner-notice-buttons">
						<a class="pixel-watch-center-btn-theme-info button button-primary bundlee" target="_blank" href="<?php echo esc_url(PIXEL_WATCH_CENTER_COLLECTIONS); ?>" id="pixel-watch-center-collection-button"> <?php esc_html_e('View All Themes', 'pixel-watch-center') ?></a>
						<a class="pixel-watch-center-btn-theme-info button button-primary live-demoo" target="_blank" href="<?php echo esc_url(PIXEL_WATCH_CENTER_BUNDLE); ?>" id="pixel-watch-center-bundle-button"> <?php esc_html_e('Buy Bundle', 'pixel-watch-center') ?></a>
					</div>
				</div>
				<div class="middle-box">
					<div class="box-1">
						<div class="box-info">
							<span class="dashicons dashicons-yes-alt"></span>
							<div>
								<p><?php esc_html_e( '30+ Premium', 'pixel-watch-center' ); ?></p>
								<p><?php esc_html_e( 'WordPress Themes', 'pixel-watch-center' ); ?></p>
							</div>
						</div>
						<div class="box-info">
							<span class="dashicons dashicons-yes-alt"></span>
							<div>
								<p><?php esc_html_e( 'Single Theme', 'pixel-watch-center' ); ?></p>
								<p><?php esc_html_e( 'Starting at $40', 'pixel-watch-center' ); ?></p>
							</div>
						</div>
						<div class="box-info">
							<span class="dashicons dashicons-yes-alt"></span>
							<div>
								<p><?php esc_html_e( 'One Time Payment -', 'pixel-watch-center' ); ?></p>
								<p><?php esc_html_e( 'no hidden charges', 'pixel-watch-center' ); ?></p>
							</div>
						</div>
					</div>
					<div class="box-2">
						<p class="box-2-para"><?php esc_html_e( 'Total Value', 'pixel-watch-center' ); ?></p>
						<h4><?php esc_html_e( '$2499', 'pixel-watch-center' ); ?></h4>
						<p><?php esc_html_e( 'Bundle Price', 'pixel-watch-center' ); ?></p>
						<span><sup><?php esc_html_e( '$', 'pixel-watch-center' ); ?></sup><h2><?php esc_html_e( '59', 'pixel-watch-center' ); ?></h2></span>
						<p class="box-para"><?php esc_html_e( 'One Time Payement', 'pixel-watch-center' ); ?></p>
						<p class="box-btn"><?php esc_html_e( 'You Save $2430', 'pixel-watch-center' ); ?></p>
					</div>
				</div>
				<div class="notice-image">
					<img src="<?php echo esc_url( get_stylesheet_directory_uri() . '/assets/images/bundle-img.png' ); ?>" alt="<?php esc_attr_e( 'Theme Screenshot', 'pixel-watch-center' ); ?>">
				</div>
            </div>
        </div>
    </div>
    <?php
}

add_action('admin_notices', 'pixel_watch_center_activation_notice');

add_action('wp_ajax_pixel_watch_center_dismiss_notice', 'pixel_watch_center_dismiss_notice');

function pixel_watch_center_notice_status() {
    delete_option('pixel_watch_center_notice_dismissed');
}
add_action('after_switch_theme', 'pixel_watch_center_notice_status');

function pixel_watch_center_dismiss_notice() {
    update_option('pixel_watch_center_notice_dismissed', true);
    wp_send_json_success();
}

function pixel_watch_center_admin_enqueue_scripts(){
	wp_enqueue_style('pixel-watch-center-admin-style', esc_url( get_template_directory_uri() ) . '/assets/css/pixel-watch-center-notice.css');
	wp_enqueue_script('pixel-watch-center-dismiss-notice-script', get_stylesheet_directory_uri() . '/assets/js/pixel-watch-center-notice.js', array('jquery'), null, true);
}
add_action( 'admin_enqueue_scripts', 'pixel_watch_center_admin_enqueue_scripts' );