<?php
/**
 *  Carousel view file
 *
 * This template can be overridden by copying it to yourtheme/smart-post-show-pro/templates/carousel.php
 *
 * @package    Smart_Post_Show_Pro
 * @subpackage Smart_Post_Show_Pro/public/template
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}
$carousel_mode        = isset( $layout['pcp_carousel_mode'] ) ? $layout['pcp_carousel_mode'] : 'standard';
$carousel_autoplay    = ( isset( $view_options['pcp_autoplay'] ) && ( $view_options['pcp_autoplay'] ) ) ? 'true' : 'false';
$autoplay_speed       = isset( $view_options['pcp_autoplay_speed'] ) ? $view_options['pcp_autoplay_speed'] : '2000';
$carousel_speed       = isset( $view_options['pcp_carousel_speed'] ) ? $view_options['pcp_carousel_speed'] : '600';
$ticker_speed         = isset( $view_options['pcp_ticker_speed'] ) ? $view_options['pcp_ticker_speed'] : '3000';
$pause_hover          = ( isset( $view_options['pcp_pause_hover'] ) && ( $view_options['pcp_pause_hover'] ) ) ? 'true' : 'false';
$slide_effect         = isset( $view_options['pcp_slide_effect'] ) ? $view_options['pcp_slide_effect'] : 'slide';
$_slides_to_scroll    = isset( $view_options['pcp_slides_to_scroll'] ) ? $view_options['pcp_slides_to_scroll'] : array(
	'lg_desktop'       => '1',
	'desktop'          => '1',
	'tablet'           => '1',
	'mobile_landscape' => '1',
	'mobile'           => '1',
);
$space_between        = isset( $margin_between_post['left-right'] ) ? $margin_between_post['left-right'] : 20;
$infinite_loop        = ( isset( $view_options['pcp_infinite_loop'] ) && ( $view_options['pcp_infinite_loop'] ) ) ? 'true' : 'false';
$carousel_auto_height = ( isset( $view_options['pcp_adaptive_height'] ) && ( $view_options['pcp_adaptive_height'] ) ) ? 'true' : 'false';
$number_of_columns    = isset( $view_options['pcp_number_of_columns'] ) ? $view_options['pcp_number_of_columns'] : array(
	'lg_desktop'       => '4',
	'desktop'          => '4',
	'tablet'           => '3',
	'mobile_landscape' => '2',
	'mobile'           => '1',
);
if ( 'slider_layout' === $layout_preset ) {
	$number_of_columns = array(
		'lg_desktop'       => '1',
		'desktop'          => '1',
		'tablet'           => '1',
		'mobile_landscape' => '1',
		'mobile'           => '1',
	);
}
$ticker_slide_width = isset( $view_options['pcp_ticker_slide_width'] ) ? $view_options['pcp_ticker_slide_width'] : '250';
$lazy_load          = ( isset( $view_options['pcp_lazy_load'] ) && ( $view_options['pcp_lazy_load'] ) ) ? 'true' : 'false';
if ( 'cube' === $slide_effect || 'flip' === $slide_effect ) {
	$carousel_auto_height = 'false';
	$lazy_load            = 'false';
}
$spsp_fade_class = '';
if ( 'fade' === $slide_effect ) {
	$spsp_fade_class = ' pcp-carousel-fade';
}
// Direction.
$carousel_direction = ( isset( $view_options['pcp_carousel_direction'] ) ) ? $view_options['pcp_carousel_direction'] : 'ltr';
if ( 'ticker' === $carousel_mode ) {
	$carousel_direction = 'rtl' === $carousel_direction ? 'prev' : 'next';
}
$is_carousel_accessibility            = ( isset( $pcp_settings['accessibility'] ) && ( $pcp_settings['accessibility'] ) ) ? 'true' : 'false';
$accessibility_prev_slide_text        = isset( $pcp_settings['prev_slide_message'] ) ? $pcp_settings['prev_slide_message'] : '';
$accessibility_next_slide_text        = isset( $pcp_settings['next_slide_message'] ) ? $pcp_settings['next_slide_message'] : '';
$accessibility_first_slide_text       = isset( $pcp_settings['first_slide_message'] ) ? $pcp_settings['first_slide_message'] : '';
$accessibility_last_slide_text        = isset( $pcp_settings['last_slide_message'] ) ? $pcp_settings['last_slide_message'] : '';
$accessibility_pagination_bullet_text = isset( $pcp_settings['pagination_bullet_message'] ) ? $pcp_settings['pagination_bullet_message'] : '';

$pcp_responsive_screen_setting = isset( $pcp_settings['pcp_responsive_screen_setting'] ) ? $pcp_settings['pcp_responsive_screen_setting'] : '';
$desktop_screen_size           = ! empty( $pcp_responsive_screen_setting ['desktop'] ) ? $pcp_responsive_screen_setting ['desktop'] : '1200';
$tablet_screen_size            = ! empty( $pcp_responsive_screen_setting ['tablet'] ) ? $pcp_responsive_screen_setting ['tablet'] : '980';
$mobile_land_screen_size       = ! empty( $pcp_responsive_screen_setting ['mobile_landscape'] ) ? $pcp_responsive_screen_setting ['mobile_landscape'] : '736';
$mobile_screen_size            = ! empty( $pcp_responsive_screen_setting ['mobile'] ) ? $pcp_responsive_screen_setting ['mobile'] : '576';
// Row.
$carousel_row = ( isset( $view_options['pcp_number_of_row'] ) ) && 'multi-rows' === $carousel_mode ? $view_options['pcp_number_of_row'] : array(
	'lg_desktop'       => '1',
	'desktop'          => '1',
	'tablet'           => '1',
	'mobile_landscape' => '1',
	'mobile'           => '1',
);


if ( $swiper_js ) {
	wp_enqueue_script( 'pcp_swiper' );
}
if ( $bx_js ) {
	wp_enqueue_script( 'pcp_bxslider' );
}
// Navigation.
$_navigation_data      = isset( $view_options['pcp_navigation_data'] ) ? $view_options['pcp_navigation_data'] : array();
$_navigation           = isset( $_navigation_data['pcp_navigation'] ) ? $_navigation_data['pcp_navigation'] : true;
$_navigation_on_mobile = isset( $_navigation_data['nev_hide_on_mobile'] ) ? $_navigation_data['nev_hide_on_mobile'] : false;
if ( $_navigation ) {
	$navigation        = 'true';
	$navigation_mobile = 'true';
} elseif ( $_navigation && $_navigation_on_mobile ) {
	$navigation        = 'true';
	$navigation_mobile = 'false';
} else {
	$navigation        = 'false';
	$navigation_mobile = 'false';
}

$navigation_icons      = isset( $view_options['navigation_icons'] ) ? $view_options['navigation_icons'] : 'angle';
$navigation_arrow      = SP_PCP_Functions::navigation_icon( $navigation_icons );
$carousel_nav_position = isset( $view_options['pcp_carousel_nav_position'] ) ? $view_options['pcp_carousel_nav_position'] : 'top_right';
$nev_visible_on_hover  = isset( $view_options['nev_visible_on_hover'] ) && $view_options['nev_visible_on_hover'] ? ' pcp_nev_visible_on_hover' : '';
// Pagination Settings.
$_pagination_data      = isset( $view_options['carousel_pagination_group'] ) ? $view_options['carousel_pagination_group'] : array();
$_pagination           = isset( $_pagination_data['pcp_pagination'] ) ? $_pagination_data['pcp_pagination'] : true;
$_pagination_on_mobile = isset( $_pagination_data['pagination_hide_on_mobile'] ) ? $_pagination_data['pagination_hide_on_mobile'] : false;
if ( $_pagination ) {
	$pagination        = 'true';
	$pagination_mobile = 'true';
} elseif ( $_pagination && $_pagination_on_mobile ) {
	$pagination        = 'true';
	$pagination_mobile = 'false';
} else {
	$pagination        = 'false';
	$pagination_mobile = 'false';
}
$bullet_types       = ( isset( $view_options['bullet_types'] ) ) ? $view_options['bullet_types'] : 'dots';
$dynamic_bullets    = 'dynamic' === $bullet_types ? 'true' : 'false';
$pcp_accessibility  = ( isset( $view_options['pcp_accessibility'] ) && ( $view_options['pcp_accessibility'] ) ) ? 'true' : 'false';
$touch_swipe        = ( isset( $view_options['touch_swipe'] ) && ( $view_options['touch_swipe'] ) ) ? 'true' : 'false';
$slider_draggable   = ( isset( $view_options['slider_draggable'] ) && ( $view_options['slider_draggable'] ) ) ? 'true' : 'false';
$slider_mouse_wheel = ( isset( $view_options['slider_mouse_wheel'] ) && ( $view_options['slider_mouse_wheel'] ) ) ? 'true' : 'false';
$slider_free_mode   = ( isset( $view_options['slider_free_mode'] ) && ( $view_options['slider_free_mode'] ) ) ? 'true' : 'false';
$center_mode        = 'false';
$mobile_landscape   = isset( $number_of_columns['mobile_landscape'] ) ? $number_of_columns['mobile_landscape'] : '2';
if ( 'center' === $carousel_mode ) {
	$center_mode = 'true';
}

$sps_current_theme = wp_get_theme(); // Get information about the active theme.
$initialized_attr  = $sps_current_theme->exists() && ( 'XStore' === $sps_current_theme->get( 'Name' ) || 'xstore' === $sps_current_theme->get( 'Template' ) ) ? 'initialized' : ''; // Check current theme exists and If it is 'XStore' or 'XStore child' theme then add "initialized" class to the swiper container.

?>
<!-- Markup Starts -->
<div id="pcp_wrapper-<?php echo esc_html( $smart_show_id ); ?>" class="<?php self::pcp_wrapper_classes( $layout_preset, $smart_show_id, $pagination_type, $item_same_height_class ); ?> <?php echo esc_attr( $carousel_mode . $nev_visible_on_hover ); ?>" data-sid="<?php echo esc_html( $smart_show_id ); ?>" data-lang="<?php echo esc_attr( $spsp_lang ); ?>" data-current_post_id="<?php the_ID(); ?>">
<?php
	SP_PCP_HTML::pcp_section_title( $section_title, $show_section_title );
	SP_PCP_HTML::pcp_preloader( $show_preloader );
?>
<?php require SP_PCP_Functions::pcp_locate_template( 'filter-bar.php' ); ?>
	<div id="sp-pcp-id-<?php echo esc_html( $smart_show_id ); ?>" class="swiper-container <?php echo esc_attr( $initialized_attr ); ?> sp-pcp-carousel <?php echo esc_html( $carousel_nav_position . $spsp_fade_class . ' ' . $layout_preset ); ?>" dir="<?php echo esc_html( $carousel_direction ); ?>" layout="<?php echo esc_html( $layout_preset ); ?>" data-carousel='{"mode":"<?php echo esc_html( $carousel_mode ); ?>", "speed":<?php echo esc_html( $carousel_speed ); ?>, "ticker_speed":<?php echo esc_html( $ticker_speed ); ?>, "ticker_width":<?php echo esc_html( $ticker_slide_width ); ?>, "items":<?php echo esc_html( $number_of_columns['lg_desktop'] ); ?>, "spaceBetween":<?php echo esc_html( $space_between ); ?>, "navigation":<?php echo esc_html( $navigation ); ?>, "pagination": <?php echo esc_html( $pagination ); ?>, "autoplay": <?php echo esc_html( $carousel_autoplay ); ?>, "autoplay_speed": <?php echo esc_html( $autoplay_speed ); ?>, "loop": <?php echo esc_html( $infinite_loop ); ?>, "autoHeight": <?php echo esc_html( $carousel_auto_height ); ?>, "lazy":  <?php echo esc_html( $lazy_load ); ?>, "effect": "<?php echo esc_html( $slide_effect ); ?>", "simulateTouch": <?php echo esc_html( $slider_draggable ); ?>, "slider_mouse_wheel": <?php echo esc_html( $slider_mouse_wheel ); ?>, "slider_free_mode": <?php echo esc_html( $slider_free_mode ); ?>, "allowTouchMove": <?php echo esc_html( $touch_swipe ); ?>, "dynamicBullets": <?php echo esc_html( $dynamic_bullets ); ?>, "bullet_types": "<?php echo esc_html( $bullet_types ); ?>", "center_mode": <?php echo esc_html( $center_mode ); ?>, "slidesRow": {"lg_desktop": <?php echo esc_html( $carousel_row['lg_desktop'] ); ?>, "desktop": <?php echo esc_html( $carousel_row['desktop'] ); ?>, "tablet": <?php echo esc_html( $carousel_row['tablet'] ); ?>, "mobile_landscape": <?php echo esc_html( $carousel_row['mobile_landscape'] ); ?>, "mobile": <?php echo esc_html( $carousel_row['mobile'] ); ?>}, "responsive": {"lg_desktop": <?php echo esc_html( $desktop_screen_size ); ?>, "desktop": <?php echo esc_html( $tablet_screen_size ); ?>, "tablet": <?php echo esc_html( $mobile_land_screen_size ); ?>, "mobile_landscape": <?php echo esc_html( $mobile_screen_size ); ?>}, "slidesPerView": {"lg_desktop": <?php echo esc_html( $number_of_columns['lg_desktop'] ); ?>, "desktop": <?php echo esc_html( $number_of_columns['desktop'] ); ?>, "tablet": <?php echo esc_html( $number_of_columns['tablet'] ); ?>, "mobile_landscape": <?php echo esc_html( $mobile_landscape ); ?>, "mobile": <?php echo esc_html( $number_of_columns['mobile'] ); ?>}, "slideToScroll": {"lg_desktop": <?php echo esc_html( $_slides_to_scroll['lg_desktop'] ); ?>, "desktop": <?php echo esc_html( $_slides_to_scroll['desktop'] ); ?>, "tablet": <?php echo esc_html( $_slides_to_scroll['tablet'] ); ?>, "mobile_landscape": <?php echo esc_html( $_slides_to_scroll['mobile_landscape'] ); ?>, "mobile": <?php echo esc_html( $_slides_to_scroll['mobile'] ); ?> }, "navigation_mobile": <?php echo esc_html( $navigation_mobile ); ?>, "pagination_mobile": <?php echo esc_html( $pagination_mobile ); ?>, "stop_onHover": <?php echo esc_html( $pause_hover ); ?>, "enabled": <?php echo esc_html( $is_carousel_accessibility ); ?>, "prevSlideMessage": "<?php echo esc_html( $accessibility_prev_slide_text ); ?>", "nextSlideMessage": "<?php echo esc_html( $accessibility_next_slide_text ); ?>", "firstSlideMessage": "<?php echo esc_html( $accessibility_first_slide_text ); ?>", "lastSlideMessage": "<?php echo esc_html( $accessibility_last_slide_text ); ?>","keyboard": "<?php echo esc_html( $pcp_accessibility ); ?>", "paginationBulletMessage": "<?php echo esc_html( $accessibility_pagination_bullet_text ); ?>" }'>
			<div class="swiper-wrapper">
				<?php self::pcp_get_posts( $options, $layout, $post_content_sorter, $pcp_query, $smart_show_id ); ?>
			</div>
			<?php
			if ( 'true' === $pagination && 'ticker' !== $carousel_mode ) {
				if ( 'scrollbar' === $bullet_types ) {
					?>
					<div class="swiper-scrollbar pcp-pagination-scrollbar"></div>
					<?php
				} else {
					?>
						<div class="pcp-pagination swiper-pagination <?php echo esc_html( $bullet_types ); ?>"></div>
					<?php
				}
			}
			?>
			<?php if ( 'true' === $navigation && 'ticker' !== $carousel_mode ) { ?>
				<div class="pcp-button-next swiper-button-next <?php echo esc_html( $carousel_nav_position ); ?>"><i class="<?php echo esc_attr( $navigation_arrow['right'] ); ?>"></i></div>
				<div class="pcp-button-prev swiper-button-prev <?php echo esc_html( $carousel_nav_position ); ?>"><i class="<?php echo esc_attr( $navigation_arrow['left'] ); ?>"></i></div><?php } ?>
	</div>
</div>
