<?php

// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

function shrk_sc_woo_xy_slider($atts) {

	$atts = shortcode_atts(array(
		'slider_id'                  => null,
		'cats_number'                => null,		// Max number of categories to show
		'cats_orderby'               => 'name',		// Accepts term fields ('name', 'slug', 'term_group', 'term_id', 'id', 'description'), 'count' for term taxonomy count
		'cats_order'                 => 'ASC',		// ASC or DESC
		'cats_hide_empty'            => '1',			//
		'cats_parent'                => '',			// Show only children of..
		'cats_ids'                   => '',			// Comma separated string of term ids to include
		'el_class'                   => '',
		'swiper_mode'                => 'vertical',
		'swiper_speed'               => '5000',
		'swiper_autoplay'            => 'no',
		'swiper_effect'              => 'slide',
		'swiper_autoheight'          => 'no',
		'slider_height_mode'         => 'custom',
		'slider_height'              => '600px',
		'show_scrollbar'             => 'no',
		'hide_pagination'            => 'yes',
		'slides_grid_width'          => '12', // 12 = one per slide
		'space_between_slides'       => '',
		'partial_view'               => 'no',
		'partial_max_width'          => '80%',
		'lazyload_next_slides'       => false,
		'preload_first_x_slides'     => 'auto',
		'inner_auto_load_slides'     => 'yes',
		'inner_per_page'             => '10',
		'inner_orderby'              => 'date',
		'inner_order'                => 'DESC',
		'inner_thumb_only'           => 'no',
		'inner_thumb_fb'             => 'yes',
		'inner_half_image'           => 'no',
		'inner_transp_content'       => 'no',
		'inner_transp_content_mob'   => 'no',
		'inner_content_bg_color'     => '',
		'inner_content_bg_color_mob' => '',
		'inner_image_bg_color'       => '',
		'inner_image_bg_size'        => '',
		'slider_bg_color'            => '',
		'cat_overlay_bg_color'       => '',
		'cat_button_text'            => 'Show me',
		'swiper_breakpoints'         => 'disable',
		'nav_thumbs'                 => 'autohide',
		'nav_thumbs_overlay_bg_color' => '',
		'nav_thumbs_show_count'      => 'no',
	), $atts);

	if ( !function_exists( 'shrk_sc_swiper_get_atts' ) || !function_exists( 'WC' ) ) {
		return '<div>' . esc_html__('Your theme does not support the XY Products Slider or WooCommerce is not active.', 'dvl-uxshop-shortcodes') . '</div>';
	}
	
	wp_enqueue_script( 'shrk-swiper' );

	$slider_id = !empty( $atts['slider_id'] ) ? $atts['slider_id'] : false;

	if ( isset( $atts['cats_ids'] ) ) {
		$ids = explode( ',', $atts['cats_ids'] );
		$ids = array_map( 'trim', $ids );
	} else {
		$ids = array();
	}

	$hide_empty = ( $atts['cats_hide_empty'] == '1' ) ? 1 : 0;

	$args = array(
		'orderby'    => $atts['cats_orderby'],
		'order'      => $atts['cats_order'],
		'hide_empty' => $hide_empty,
		'include'    => $ids,
		'pad_counts' => true,
		'child_of'   => $atts['cats_parent']
	);

	$product_categories = get_terms( 'product_cat', $args );

	$product_categories = is_wp_error( $product_categories ) ? array() : $product_categories;

	if ( '' !== $atts['cats_parent'] ) {
		$product_categories = wp_list_filter( $product_categories, array( 'parent' => $atts['cats_parent'] ) );
	}

	if ( $hide_empty ) {
		foreach ( $product_categories as $key => $category ) {
			if ( $category->count == 0 ) {
				unset( $product_categories[ $key ] );
			}
		}
	}

	if ( $atts['cats_number'] ) {
		$product_categories = array_slice( $product_categories, 0, $atts['cats_number'] );
	}



	$inner_swiper_atts = array(
		'swiper_mode'            => 'horizontal',
		'swiper_speed'           => '5000',
		'swiper_autoplay'        => 'no',
		'swiper_autoheight'      => 'no',
		'slides_grid_width'      => '12',
		'space_between_slides'   => '',
		'partial_view'           => 'no',
		'partial_max_width'      => '80%',
		'lazyload_next_slides'   => false,
		'preload_first_x_slides' => 'auto',
		'show_scrollbar'         => 'no',
		'hide_pagination'        => 'yes',
		'auto_load_slides'       => $atts['inner_auto_load_slides'],
		'category_id'            => '',
		'page'                   => '1',
		'per_page'               => $atts['inner_per_page'],
		'orderby'                => $atts['inner_orderby'],
		'order'                  => $atts['inner_order'],
		'swiper_breakpoints'     => 'disable',
		'cover_atts'             => array( 
				'thumb_fb'   => ( $atts['inner_thumb_fb'] == 'yes' ? true : false ),
				'thumb_only' => ( $atts['inner_thumb_only'] == 'yes' ? true : false ),
			),
		);

	ob_start();

	// Loop throught categories to get
	// inner swipers
	// 
	$outer_pagination = $cat_cover_srcset = '';
	$i = 0;
	if ( $product_categories ) {
		foreach ( $product_categories as $category ) {
			$cat_cover                        = function_exists('woo_shrk_get_category_image') && woo_shrk_get_category_image( $category->term_id ) ? woo_shrk_get_category_image( $category->term_id, 'shrk_section_bg' ) : '';
			$cat_cover_thumb                  = function_exists('woo_shrk_get_category_image') && woo_shrk_get_category_image( $category->term_id ) ? woo_shrk_get_category_image( $category->term_id, 'large' ) : '';
			$inner_swiper_atts['category_id'] = $category->term_id;
			$sw_pc                            = shrk_swiper_product_category( $inner_swiper_atts );
			$inner_swiper_content             = $sw_pc['content'];
			$inner_swiper_product_count       = intval( $sw_pc['count'] );
			if ( function_exists( 'get_woocommerce_term_meta' ) && function_exists( 'shrk_get_image_aspect' ) ) {
				$cat_cover_id     = get_woocommerce_term_meta( $category->term_id, 'thumbnail_id', true );
				$cat_cover_srcset = wp_get_attachment_image_srcset( $cat_cover_id, 'shrk_section_bg' );
				$cat_cover_ar     = shrk_get_image_aspect( $cat_cover_id, 'shrk_section_bg' );
			}
			?>

			<div class="swiper-slide">
			<?php
			echo '<div ' . shrk_sc_swiper_get_atts( $inner_swiper_atts, array('shrk-swiper-container', 'inner', 'img-cover') ) . '>';
			echo '<div class="swiper-wrapper">';
			?>
			<div class="swiper-slide">
				<div class="category-cover lazyload-bg" data-image-bg="<?php echo esc_url( $cat_cover ); ?>" data-srcset="<?php echo esc_attr( $cat_cover_srcset ); ?>" data-image-ar="<?php echo esc_attr( $cat_cover_ar ); ?>">
					<div class="cover-inner">
						<h1 class="cover-title"><?php echo esc_html( $category->name ); ?></h1>
						<a href="#" class="button open-inner-slide"><?php echo esc_attr( $atts['cat_button_text'] ); ?></a>
					</div>
				</div>			
			</div>
			<?php
			echo $inner_swiper_content; // Loop template content-slide-product.php
			echo '</div>';
			echo '<div class="swiper-product-count" data-count="' . esc_attr( $inner_swiper_product_count ) . '"><span class="count">0</span> / ' . esc_html( $inner_swiper_product_count ) . '</div>';
			echo '</div>';
			?>
			</div>
			<?php

			$outer_pagination .= '<div class="nav-thumb" data-slide-id="' . esc_attr( $i ) . '"><div class="thumb-bg" style="background-image: url(' . esc_url( $cat_cover_thumb ) . ')"></div><span class="cat-name">' . esc_html( $category->name ) . '</span><span class="count">(' . esc_html( $inner_swiper_product_count ) . ')</span></div>';
			$i++;
		}
	}

	woocommerce_reset_loop();
	$slides_cat = ob_get_clean();
	$swiper_outer_classes = array('shrk-swiper-container', 'img-cover');

	if ( $atts['nav_thumbs'] == 'show' ) {
		$swiper_outer_classes[] = 'swiper-nav-sticky';
	}

	if ( $atts['nav_thumbs_show_count'] == '1' ) {
		$swiper_outer_classes[] = 'swiper-nav-show-count';
	}
	
	// Outer swiper
	$output = '';
	$output .= '<div ' . ( $slider_id ? 'id="' . esc_attr( $slider_id ) . '"' : '' ) . ' class="shrk-swiper-container-wrapper xy-slider products outer ' . (count($product_categories) == 1 ? 'one-slide ' : ' ') . esc_attr( $atts['el_class'] ) . '">';
	$output .= '<div ' . shrk_sc_swiper_get_atts( $atts, $swiper_outer_classes ) . '>';
	$output .= '<div class="swiper-wrapper">';
	$output .= $slides_cat;
	$output .= '</div>';
	
	if ( $atts['nav_thumbs'] != 'hide' ) {
		$output .= '
		<div class="swiper-nav-wrapper">
			<div class="swiper-nav-outer">
				<div class="swiper-nav-thumbs-wrapper">' . $outer_pagination . '
					<div class="active-bar">
					</div>
				</div>
				<div class="toggle-button">
				</div>
			</div>
		</div>';
	}
	$output .= '</div></div>';

	return '<div class="woocommerce">' . $output . '</div>';
}

add_action( 'init', function () {
	add_shortcode('shrk_woo_catproducts', 'shrk_sc_woo_xy_slider');
});

add_filter( 'shrk_filter_vc_mappings', function ( $shrk_vc_shortcodes ) {
	$shrk_vc_shortcodes["shrk_flex"] =  array(
		"name" => esc_html__("XY Products Slider", 'dvl-uxshop-shortcodes'),
		"category" => esc_html__('Theme Specific', 'dvl-uxshop-shortcodes'),
		"icon" => "icon-wpb-shrk",
		"base" => "shrk_woo_catproducts",
		"show_settings_on_create" => true,
		"params" => array(
				array(
					"type" => "textfield",
					"class" => "hidden",
					"param_name" => "slider_id",
					"value" => uniqid('swiper-'),
					"group" => esc_html__( "Slider options", 'dvl-uxshop-shortcodes' ),
				),
				array(
					"type" => "dropdown",
					"heading" => esc_html__("Slider effect", 'dvl-uxshop-shortcodes'),
					"param_name" => "swiper_effect",
					"value" => array(
						esc_html__("Slide", 'dvl-uxshop-shortcodes')     => "slide",
						esc_html__("Fade", 'dvl-uxshop-shortcodes')      => "fade",
						esc_html__("Coverflow", 'dvl-uxshop-shortcodes') => "coverflow",
						esc_html__("Flip", 'dvl-uxshop-shortcodes')      => "flip",
					),
					"group" => esc_html__( "Slider options", 'dvl-uxshop-shortcodes' ),
				),
				array(
					"type" => "dropdown",
					"class" => "",
					"heading" => esc_html__("Slider height mode", 'dvl-uxshop-shortcodes'),
					"param_name" => "slider_height_mode",
					"value" => array(
						esc_html__("Custom", 'dvl-uxshop-shortcodes') => "custom",
						esc_html__("Window height (minus header height)", 'dvl-uxshop-shortcodes') => "windowheight_mh"
					),
					"description" => esc_html__("You can enter a custom height or set the slider to match the parent row height.", 'dvl-uxshop-shortcodes'),
					"group" => esc_html__( "Slider options", 'dvl-uxshop-shortcodes' ),
				),
				array(
					"type" => "textfield",
					"class" => "",
					"heading" => esc_html__("Slider height", 'dvl-uxshop-shortcodes'),
					"description" => esc_html__("You can enter a value in pixels, em, or vh. For example entering `60vh` will make it 60% of the window height.", 'dvl-uxshop-shortcodes'),
					"param_name" => "slider_height",
					"value" => '600px',
					"dependency" => Array('element' => "slider_height_mode", 'value' => array('custom')),
					"group" => esc_html__( "Slider options", 'dvl-uxshop-shortcodes' ),
				),
				array(
					"type" => "textfield",
					"heading" => esc_html__("Categories open button text", 'dvl-uxshop-shortcodes'),
					"param_name" => "cat_button_text",
					"value" => esc_html__( "Show me", 'dvl-uxshop-shortcodes' ),
					"group" => esc_html__( "Slider options", 'dvl-uxshop-shortcodes' ),
				),
				array(
					"type" => 'colorpicker',
					"heading" => esc_html__("Categories cover overlay color", 'dvl-uxshop-shortcodes'),
					"description" => esc_html__("Set the color and opacity applied on the categories images (vertical slider).", 'dvl-uxshop-shortcodes'),
					"param_name" => "cat_overlay_bg_color",
					"group" => esc_html__( "Slider options", 'dvl-uxshop-shortcodes' ),
				),
				array(
					"type" => 'checkbox',
					"heading" => esc_html__("Don't use cover image. (Use only product thumbnail)", 'dvl-uxshop-shortcodes'),
					"param_name" => "inner_thumb_only",
					"value" => Array(esc_html__("Yes", 'dvl-uxshop-shortcodes') => 'yes'),
					"group" => esc_html__( "Slider options", 'dvl-uxshop-shortcodes' ),
				),
				array(
					"type" => 'checkbox',
					"heading" => esc_html__("Fallback to product thumbnail if no cover image available.", 'dvl-uxshop-shortcodes'),
					"param_name" => "inner_thumb_fb",
					"value" => Array(esc_html__("Yes", 'dvl-uxshop-shortcodes') => 'yes'),
					"group" => esc_html__( "Slider options", 'dvl-uxshop-shortcodes' ),
				),	
				array(
					"type" => 'checkbox',
					"heading" => esc_html__("Make image 50% of the slide's width.", 'dvl-uxshop-shortcodes'),
					"param_name" => "inner_half_image",
					"value" => Array(esc_html__("Yes", 'dvl-uxshop-shortcodes') => 'yes'),
					"group" => esc_html__( "Slider options", 'dvl-uxshop-shortcodes' ),
				),	
				array(
					"type" => 'colorpicker',
					"heading" => esc_html__("Set content box background color.", 'dvl-uxshop-shortcodes'),
					"param_name" => "inner_content_bg_color",
					"group" => esc_html__( "Slider options", 'dvl-uxshop-shortcodes' ),
				),
				array(
					"type" => 'colorpicker',
					"heading" => esc_html__("Set content box background color for mobile devices.", 'dvl-uxshop-shortcodes'),
					"param_name" => "inner_content_bg_color_mob",
					"group" => esc_html__( "Slider options", 'dvl-uxshop-shortcodes' ),
				),
				array(
					"type" => 'checkbox',
					"heading" => esc_html__("Transparent content box on mobile", 'dvl-uxshop-shortcodes'),
					"param_name" => "inner_transp_content_mob",
					"value" => Array(esc_html__("Yes", 'dvl-uxshop-shortcodes') => 'yes'),
					"group" => esc_html__( "Slider options", 'dvl-uxshop-shortcodes' ),
				),	
				array(
					"type" => 'colorpicker',
					"heading" => esc_html__("Set slider background color.", 'dvl-uxshop-shortcodes'),
					"param_name" => "slider_bg_color",
					"group" => esc_html__( "Slider options", 'dvl-uxshop-shortcodes' ),
				),

				array(
					"type" => "dropdown",
					"class" => "",
					"heading" => esc_html__("Image background size", 'dvl-uxshop-shortcodes'),
					"description" => esc_html__("You can select `contain` if you want the product image never to get cropped by the container boundaries. You can also set a color below, to match the background color of your product image.", 'dvl-uxshop-shortcodes'),
					"param_name" => "inner_image_bg_size",
					"value" => array(
						esc_html__("Cover", 'dvl-uxshop-shortcodes') => "cover",
						esc_html__("Contain", 'dvl-uxshop-shortcodes') => "contain",
					),
					"group" => esc_html__( "Slider options", 'dvl-uxshop-shortcodes' ),
				),
				array(
					"type" => 'colorpicker',
					"heading" => esc_html__("Image background color.", 'dvl-uxshop-shortcodes'),
					"param_name" => "inner_image_bg_color",
					"group" => esc_html__( "Slider options", 'dvl-uxshop-shortcodes' ),
					"dependency" => Array('element' => "inner_image_bg_size", 'value' => array('contain')),
				),
				array(
					"type" => "textfield",
					"class" => "",
					"heading" => esc_html__("Posts per page", 'dvl-uxshop-shortcodes'),
					"description" => esc_html__("How many slides to load in each ajax request.", 'dvl-uxshop-shortcodes'),
					"param_name" => "inner_per_page",
					"value" => '10',
					"group" => esc_html__( "Slider options", 'dvl-uxshop-shortcodes' ),
				),
				array(
					"type" => "textfield",
					"heading" => esc_html__("Extra class name", 'dvl-uxshop-shortcodes'),
					"param_name" => "el_class",
					"description" => esc_html__("If you wish to style particular content element differently, then use this field to add a class name and then refer to it in your css file.", 'dvl-uxshop-shortcodes'),
					"group" => esc_html__( "Slider options", 'dvl-uxshop-shortcodes' ),
				),
				array(
					"type" => "woo_categories",
					"heading" => esc_html__("Limit product categories.", 'dvl-uxshop-shortcodes'),
					"param_name" => "cats_ids",
					"multiple" => true,
					"output" => "id",
					"description" => esc_html__("Select one or more categories to show only these. Selecting none displays all. Use CTRL+click to select/de-select multiple items.", 'dvl-uxshop-shortcodes'),
					"value" => "",
					"group" => esc_html__( "Slider content", 'dvl-uxshop-shortcodes' ),
				),
				array(
					"type" => "woo_categories",
					"heading" => esc_html__("Only children of", 'dvl-uxshop-shortcodes'),
					"param_name" => "cats_parent",
					"multiple" => false,
					"output" => "id",
					"description" => esc_html__( "Select a parent category here to show only its children.", 'dvl-uxshop-shortcodes' ),
					"value" => "",
					"group" => esc_html__( "Slider content", 'dvl-uxshop-shortcodes' ),
				),
				array(
					"type" => 'checkbox',
					"heading" => esc_html__("Hide empty categories.", 'dvl-uxshop-shortcodes'),
					"param_name" => "cats_hide_empty",
					"value" => Array(esc_html__("Yes", 'dvl-uxshop-shortcodes') => '1'),
					"group" => esc_html__( "Slider content", 'dvl-uxshop-shortcodes' ),
				),		
				array(
					"type" => "textfield",
					"class" => "",
					"heading" => esc_html__("Maximum number of categories to show.", 'dvl-uxshop-shortcodes'),
					"description" => esc_html__("Leave empty to show all.", 'dvl-uxshop-shortcodes'),
					"param_name" => "cats_number",
					"value" => '',
					"group" => esc_html__( "Slider content", 'dvl-uxshop-shortcodes' ),
					),
				array(
					"type" => "dropdown",
					"class" => "",
					"heading" => esc_html__("Categories Order By", 'dvl-uxshop-shortcodes'),
					"param_name" => "cats_orderby",
					"value" => array(
						esc_html__("Name", 'dvl-uxshop-shortcodes')        => "name",
						esc_html__("Slug", 'dvl-uxshop-shortcodes')        => "slug", 
						esc_html__("Term group", 'dvl-uxshop-shortcodes')  => "term_group", 
						esc_html__("Term ID", 'dvl-uxshop-shortcodes')     => "term_id", 
						esc_html__("Description", 'dvl-uxshop-shortcodes') => "description", 
						esc_html__("Count", 'dvl-uxshop-shortcodes')       => "count", 
					),
					"group" => esc_html__( "Slider content", 'dvl-uxshop-shortcodes' ),
				),
				array(
					"type" => "dropdown",
					"class" => "",
					"heading" => esc_html__("Categories Order", 'dvl-uxshop-shortcodes'),
					"param_name" => "cats_order",
					"value" => array(
						esc_html__("Descending", 'dvl-uxshop-shortcodes') => "desc",
						esc_html__("Ascending", 'dvl-uxshop-shortcodes') => "asc",
					),
					"group" => esc_html__( "Slider content", 'dvl-uxshop-shortcodes' ),
				),
				array(
					"type" => "dropdown",
					"class" => "",
					"heading" => esc_html__("Products Order By", 'dvl-uxshop-shortcodes'),
					"param_name" => "inner_orderby",
					"value" => array(
						esc_html__("Date", 'dvl-uxshop-shortcodes')                     => "date", 
						esc_html__("Product ID", 'dvl-uxshop-shortcodes')               => "ID",
						esc_html__("Product Title", 'dvl-uxshop-shortcodes')            => "title",
						esc_html__("Product slug", 'dvl-uxshop-shortcodes')             => "name",
						esc_html__("Random", 'dvl-uxshop-shortcodes')                   => "rand",
						esc_html__("Comments (reviews) count", 'dvl-uxshop-shortcodes') => "comment_count",
						esc_html__("Menu order", 'dvl-uxshop-shortcodes')               => "menu_order",
					),
					"group" => esc_html__( "Slider content", 'dvl-uxshop-shortcodes' ),
				),
				array(
					"type" => "dropdown",
					"class" => "",
					"heading" => esc_html__("Products Order", 'dvl-uxshop-shortcodes'),
					"param_name" => "inner_order",
					"value" => array(
						esc_html__("Descending", 'dvl-uxshop-shortcodes') => "desc",
						esc_html__("Ascending", 'dvl-uxshop-shortcodes') => "asc",
					),
					"group" => esc_html__( "Slider content", 'dvl-uxshop-shortcodes' ),
				),
				array(
					"type" => "dropdown",
					"class" => "",
					"heading" => esc_html__("Thumbnails visibility", 'dvl-uxshop-shortcodes'),
					"param_name" => "nav_thumbs",
					"value" => array(
						esc_html__("Auto show/hide", 'dvl-uxshop-shortcodes') => "autohide", 
						esc_html__("Always Show", 'dvl-uxshop-shortcodes')    => "show", 
						esc_html__("Always Hide", 'dvl-uxshop-shortcodes')    => "hide", 
					),
					"group" => esc_html__( "Category thumbnails", 'dvl-uxshop-shortcodes' ),
				),
				array(
					"type" => 'colorpicker',
					"heading" => esc_html__("Category thumbs overlay color", 'dvl-uxshop-shortcodes'),
					"description" => esc_html__("Set the color and opacity applied on the category thumbnail images (vertical slider).", 'dvl-uxshop-shortcodes'),
					"param_name" => "nav_thumbs_overlay_bg_color",
					"group" => esc_html__( "Category thumbnails", 'dvl-uxshop-shortcodes' ),
				),
				array(
					"type" => 'checkbox',
					"heading" => esc_html__("Show product count in category thumbnail.", 'dvl-uxshop-shortcodes'),
					"param_name" => "nav_thumbs_show_count",
					"value" => Array(esc_html__("Yes", 'dvl-uxshop-shortcodes') => '1'),
					"group" => esc_html__( "Category thumbnails", 'dvl-uxshop-shortcodes' ),
				),		
			)
	);

	return $shrk_vc_shortcodes;
} );

/**
 * Process $post content and extract custom css
 * attributes for XY Slider
 * 
 * @param  object $post the post object to process
 * @return string       CSS rules
 */
function shrk_sc_get_xyslider_css( $post ) {

	$swiper_style = array();
	$pattern  = '\[(\[?)(shrk_woo_catproducts)(?![\w-])([^\]\/]*(?:\/(?!\])[^\]\/]*)*?)(?:(\/)\]|\](?:([^\[]*+(?:\[(?!\/\2\])[^\[]*+)*+)\[\/\2\])?)(\]?)';

	if ( isset( $post->post_content ) && preg_match_all( '/'. $pattern .'/s', $post->post_content, $matches ) ) {
		foreach ( $matches[3] as $val ) {
			$atts = array();
			$args = explode( ' ', $val );

			foreach ($args as $arg) {
				$arg_parsed = explode( '=', $arg );

				if ( ! empty( $arg_parsed[0] ) ) {
					$atts[$arg_parsed[0]] = trim( $arg_parsed[1], " \t\n\r\0\x0B\"" );
				}
			}

			if ( ! empty( $atts['slider_id'] ) ) {

				if ( !empty( $atts['cat_overlay_bg_color'] ) ) {
					$swiper_style[] = '#' . esc_attr( $atts['slider_id'] ) . ' .shrk-swiper-container.inner .category-cover:after {background-color:' . esc_attr( $atts['cat_overlay_bg_color'] ) . ';}';
				}

				if ( !empty( $atts['slider_bg_color'] ) ) {
					$swiper_style[] = '#' . esc_attr( $atts['slider_id'] ) . ' .shrk-swiper-container.inner {background-color:' . esc_attr( $atts['slider_bg_color'] ) . ';}';
				}

				if ( !empty( $atts['inner_content_bg_color'] ) ) {
					$swiper_style[] = '#' . esc_attr( $atts['slider_id'] ) . ' .shrk-swiper-container.inner .slide-content {background-color:' . esc_attr( $atts['inner_content_bg_color'] ) . ';}';
				}

				if ( !empty( $atts['inner_content_bg_color_mob'] ) ) {
					$swiper_style[] = '@media screen and (max-width: 767px) { #' . esc_attr( $atts['slider_id'] ) . ' .shrk-swiper-container.inner .slide-content {background-color:' . esc_attr( $atts['inner_content_bg_color_mob'] ) . ';} }';
				}

				if ( !empty( $atts['inner_image_bg_color'] ) ) {
					$swiper_style[] = '#' . esc_attr( $atts['slider_id'] ) . ' .shrk-swiper-container.inner .slide-background {background-color:' . esc_attr( $atts['inner_image_bg_color'] ) . ';}';
					$swiper_style[] = '#' . esc_attr( $atts['slider_id'] ) . ' .shrk-swiper-container.inner .slide-background:before {background-color:' . esc_attr( $atts['inner_image_bg_color'] ) . ';}';
				}

				if ( !empty( $atts['inner_image_bg_size'] ) ) {
					$swiper_style[] = '#' . esc_attr( $atts['slider_id'] ) . ' .shrk-swiper-container.inner .slide-background {background-size:' . esc_attr( $atts['inner_image_bg_size'] ) . ';}';
				}

				if ( !empty( $atts['nav_thumbs_overlay_bg_color'] ) ) {
					$swiper_style[] = '#' . esc_attr( $atts['slider_id'] ) . ' .swiper-nav-outer .nav-thumb:after {background-color:' . esc_attr( $atts['nav_thumbs_overlay_bg_color'] ) . ';}';
				}

			}

			unset( $atts );
		}
	}

	return !empty( $swiper_style ) && function_exists( 'shrk_simple_minify' ) ? shrk_simple_minify( implode(' ', $swiper_style) ) : '';
}

/**
 * Tap into vc_base_build_shortcodes_custom_css
 * to save XY Slider's custom CSS output to 
 * _wpb_shortcodes_custom_css meta.
 */
function shrk_sc_save_xyslider_css( $css ) {
	global $post;
	return $css . ' ' . shrk_sc_get_xyslider_css( $post );
}
add_filter( 'vc_base_build_shortcodes_custom_css', 'shrk_sc_save_xyslider_css' );

?>