<?php
/**
 * Enqueue scripts and styles.
 */
function author_portfolio_scripts() {
	if (!is_page_template( 'canvas.php' )) :
	$showBookSlider = get_theme_mod('books_slider_on_off', false);
	if ((is_home() && true == $showBookSlider) || (class_exists('WooCommerce') && is_product())) {
		wp_enqueue_style( 'slick', esc_url(get_theme_file_uri( 'assets/css/slick.css' )) );
	}
	$awt_settings = get_option('awt_global_settings', []);




	wp_enqueue_style( 'author-portfolio-style', get_stylesheet_uri() );
	if (class_exists('Rswpthemes_Author_Website_Templates')) {
		
		$blog_single_template_id = $awt_settings['awt_blog_single_template_id'] ?? '';
		$page_404_template_id = $awt_settings['awt_404_template_id'] ?? '';

		if (empty($blog_single_template_id) && is_single()) {
			wp_enqueue_style('single-content-area', esc_url(get_theme_file_uri('assets/css/content-area.css')));
		}elseif(empty($blog_single_template_id) && is_404()){
			wp_enqueue_style('single-content-area', esc_url(get_theme_file_uri('assets/css/content-area.css')));
		}

	}
	wp_enqueue_script( 'imagesloaded', esc_url( get_template_directory_uri() ) . '/assets/js/imagesloaded.pkgd.min.js', array( 'jquery' ), '1.0', true );
	wp_enqueue_script( 'masonry' );
	wp_enqueue_script( 'author-portfolio-menu', esc_url( get_template_directory_uri() ) . '/assets/js/menu.js', array( 'jquery' ), '1.0', true );
	if ((is_home() && true == $showBookSlider) || (class_exists('WooCommerce') && is_product())) {
		wp_enqueue_script( 'slick', esc_url( get_template_directory_uri() ) . '/assets/js/slick.js', array( 'jquery' ), '1.0', true );
	}

	wp_enqueue_script( 'author-portfolio-active', esc_url( get_template_directory_uri() ) . '/assets/js/active.js', array( 'jquery' ), '1.0', true );
	if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
		wp_enqueue_script( 'comment-reply' );
	}
	endif;
}
add_action( 'wp_enqueue_scripts', 'author_portfolio_scripts' );

add_action('customize_controls_enqueue_scripts', 'author_portfolio_customizer_scripts');
function author_portfolio_customizer_scripts(){
	wp_enqueue_style('customizer-style', esc_url(get_theme_file_uri('assets/customizer/customizer-style.css')));
}

add_action('enqueue_block_editor_assets', 'author_portfolio_global_scripts');
add_action('wp_enqueue_scripts', 'author_portfolio_global_scripts');

function author_portfolio_global_scripts(){

	wp_enqueue_style( 'bootstrap-grid', esc_url(get_theme_file_uri( 'assets/css/bootstrap-grid.css' )) );
	wp_enqueue_style( 'fontawesome-v4', esc_url(get_theme_file_uri( 'assets/css/fontawesome.css' )) );
	wp_enqueue_style( 'block-style', esc_url(get_theme_file_uri( 'assets/blocks-style/block-styles.css' )) );
	/**
	 * Title Border Color
	 */
	$getTitleBorderColor = get_theme_mod('secondary_text_color', '#fb4747');

	$inline_style_data = '
		.author-portfolio-standard-post__post-title h2 a, ul.recent-post-widget li .recent-widget-content h2{
            background-image: linear-gradient(to right, '.$getTitleBorderColor.' 0%, '.$getTitleBorderColor.' 100%);
        }
	';
	wp_add_inline_style('block-style', $inline_style_data);
}


add_action('wp_print_footer_scripts', 'author_portfolio_pro_print_scripts');
function author_portfolio_pro_print_scripts(){
	$showBookSlider = get_theme_mod('books_slider_on_off', false);
	if (is_home() && true == $showBookSlider) :
		?>
		<script type="text/javascript" id="author-portfolio-book-slider">
			var booksSliders = jQuery('.books-slider-active');
		    booksSliders.each(function(index) {
		        var slideToShow = jQuery(this).attr('data-slideToshow');
		        jQuery(this).slick({
		            slidesToShow: slideToShow,
		            slidesToScroll: 1,
		            autoplay: true,
		            arrows: true,
		            fade: false,
		            nextArrow: '<div class="slick-next"><i class="fa fa-arrow-right"></i></div>',
		            prevArrow: '<div class="slick-prev"><i class="fa fa-arrow-left"></i></div>',
		            responsive: [{
		                    breakpoint: 1024,
		                    settings: {
		                        slidesToShow: 3,
		                    }
		                },
		                {
		                    breakpoint: 600,
		                    settings: {
		                        slidesToShow: 2,
		                    }
		                },
		                {
		                    breakpoint: 480,
		                    settings: {
		                        slidesToShow: 1,
		                        adaptiveHeight: true
		                    }
		                }
		            ]
		        });
		    });
		</script>
    <?php
	endif;
	/**
	 * Print Below Script if its woocommerce product page
	 */
	if (class_exists('WooCommerce') && is_product()) {
		?>
		<script type="text/javascript" id="author-portfolio-product-page-sliders">
			jQuery('.active-single-gallery').slick({
		        slidesToShow: 1,
		        slidesToScroll: 1,
		        dots: true,
		        arrows: true,
		        fade: true,
		        nextArrow: '<div class="slick-next"><i class="fa fa-arrow-right"></i></div>',
		        prevArrow: '<div class="slick-prev"><i class="fa fa-arrow-left"></i></div>',
		    });
			jQuery('.active-product-related-post-slider').slick({
		        slidesToShow: 4,
		        slidesToScroll: 1,
		        dots: false,
		        arros: true,
		        centerMode: false,
		        focusOnSelect: true,
		        nextArrow: '<div class="slick-next"><i class="fa fa-arrow-right"></i></div>',
		        prevArrow: '<div class="slick-prev"><i class="fa fa-arrow-left"></i></div>',
		    });
		</script>
		<?php
	}
}

