<?php
/**
 *  Carousel view
 *
 * @package    eventful-for-elementor
 * @subpackage eventful-for-elementor/src/Frontend/templates
 */

use ThemeAtelier\EventfulForElementor\Frontend\Helpers\EventfulForElementorFunctions;
use ThemeAtelier\EventfulForElementor\Frontend\Helpers\EventfulForElementorLoopHtml;

if (!defined('ABSPATH')) {
	exit;
}

$carousel_mode        = isset($efpe_settings['carousel_mode']) ? $view_options['carousel_mode'] : $view_options['carousel_mode'];
$ticker_column_width         = isset($view_options['ticker_column_width']) ? $view_options['ticker_column_width'] : '250';
$carousel_autoplay    = (isset($view_options['auto_play']) && ($view_options['auto_play'])) ? 'true' : 'false';
$autoplay_speed       = isset($view_options['autoplay_speed']) ? $view_options['autoplay_speed'] : '2000';
$carousel_speed       = isset($view_options['carousel_speed']) ? $view_options['carousel_speed'] : '600';
$ticker_speed         = isset($view_options['ticker_speed']) ? $view_options['ticker_speed'] : '3000';
$slide_effect         = isset($view_options['transition_effect']) ? $view_options['transition_effect'] : 'slide';
$pause_hover          = (isset($view_options['pause_hover']) && ($view_options['pause_hover'])) ? 'true' : 'false';
$infinite_loop         = (isset($view_options['infinite_loop']) && ($view_options['infinite_loop'])) ? 'true' : 'false';
$carousel_auto_height = (isset($view_options['adaptive_height']) && ($view_options['adaptive_height'])) ? 'true' : 'false';

$column_lg_desktop = (isset($view_options['column_lg_desktop'])) ? $view_options['column_lg_desktop'] : '3';
$column_desktop = (isset($view_options['column_desktop'])) ? $view_options['column_desktop'] : '3';
$column_tablet = (isset($view_options['column_tablet'])) ? $view_options['column_tablet'] : '3';
$column_mobile_landscape = (isset($view_options['column_mobile_landscape'])) ? $view_options['column_mobile_landscape'] : '2';
$column_mobile = (isset($view_options['column_mobile'])) ? $view_options['column_mobile'] : '1';
// Row.
$row_lg_desktop = (isset($view_options['row_lg_desktop'])) ? $view_options['row_lg_desktop'] : '1';
$row_desktop = (isset($view_options['row_desktop'])) ? $view_options['row_desktop'] : '1';
$row_tablet = (isset($view_options['row_tablet'])) ? $view_options['row_tablet'] : '1';
$row_mobile_landscape = (isset($view_options['row_mobile_landscape'])) ? $view_options['row_mobile_landscape'] : '1';
$row_mobile = (isset($view_options['row_mobile'])) ? $view_options['row_mobile'] : '1';
// Slides to scroll
$slides_to_scroll_lg_desktop = (isset($view_options['slides_to_scroll_lg_desktop'])) ? $view_options['slides_to_scroll_lg_desktop'] : '1';
$slides_to_scroll_desktop = (isset($view_options['slides_to_scroll_desktop'])) ? $view_options['slides_to_scroll_desktop'] : '1';
$slides_to_scroll_tablet = (isset($view_options['slides_to_scroll_tablet'])) ? $view_options['slides_to_scroll_tablet'] : '1';
$slides_to_scroll_mobile_landscape = (isset($view_options['slides_to_scroll_mobile_landscape'])) ? $view_options['slides_to_scroll_mobile_landscape'] : '1';
$slides_to_scroll_mobile = (isset($view_options['slides_to_scroll_mobile'])) ? $view_options['slides_to_scroll_mobile'] : '1';
$thumb_lazy_load = (isset($view_options['thumb_lazy_load']) && ($view_options['thumb_lazy_load'])) ? 'true' : 'false';
$lazy_load            = (isset($efpe_settings['thumb_lazy_load']) && ($efpe_settings['thumb_lazy_load'])) ? 'true' : $thumb_lazy_load;
if ('cube' === $slide_effect || 'flip' === $slide_effect) {
	$carousel_auto_height = 'false';
	$lazy_load            = 'false';
}
$spta_fade_class = '';
if ('fade' === $slide_effect) {
	$spta_fade_class = ' efpe-carousel-fade';
}
// Direction.
$carousel_direction = (isset($efpe_settings['carousel_direction'])) ? $efpe_settings['carousel_direction'] : $view_options['carousel_direction'];
if ('ticker' === $carousel_mode) {
	$carousel_direction = 'rtl' === $carousel_direction ? 'prev' : 'next';
}
$is_carousel_accessibility            = (isset($view_options['accessibility']) && ($view_options['accessibility'])) ? 'true' : 'false';
$accessibility_prev_slide_text        = isset($view_options['prev_slide_message']) ? $view_options['prev_slide_message'] : '';
$accessibility_next_slide_text        = isset($view_options['next_slide_message']) ? $view_options['next_slide_message'] : '';
$accessibility_first_slide_text       = isset($view_options['first_slide_message']) ? $view_options['first_slide_message'] : '';
$accessibility_last_slide_text        = isset($view_options['last_slide_message']) ? $view_options['last_slide_message'] : '';
$accessibility_pagination_bullet_text = isset($view_options['pagination_bullet_message']) ? $view_options['pagination_bullet_message'] : '';

$efpe_responsive_screen_setting = isset($view_options['efpe_responsive_screen_setting']) ? $view_options['efpe_responsive_screen_setting'] : '';
$desktop_screen_size           = '1200';
$tablet_screen_size            = '980';
$mobile_land_screen_size       = '736';
$mobile_screen_size            = '576';

// Navigation.
$_navigation = isset($view_options['navigation']) ? $view_options['navigation'] : 'show';
switch ($_navigation) {
	case 'show':
		$navigation        = 'true';
		$navigation_mobile = 'true';
		break;
	case 'hide':
		$navigation        = 'false';
		$navigation_mobile = 'false';
		break;
	case 'hide_on_mobile':
		$navigation        = 'true';
		$navigation_mobile = 'false';
		break;
}

$navigation_icons      = isset($view_options['navigation_icons']) ? $view_options['navigation_icons'] : 'fa-angle';
$carousel_nav_position = isset($view_options['efpe_carousel_nav_position']) ? $view_options['efpe_carousel_nav_position'] : 'top_right';

// Pagination Settings.
$_pagination = isset($view_options['pagination']) ? $view_options['pagination'] : 'show';
switch ($_pagination) {
	case 'show':
		$pagination        = 'true';
		$pagination_mobile = 'true';
		break;
	case 'hide':
		$pagination        = 'false';
		$pagination_mobile = 'false';
		break;
	case 'hide_on_mobile':
		$pagination        = 'true';
		$pagination_mobile = 'false';
		break;
}
$dynamic_bullets    = (isset($view_options['efpe_dynamicBullets']) && ($view_options['efpe_dynamicBullets'])) ? 'true' : 'false';
$bullet_types       = (isset($view_options['bullet_types'])) ? $view_options['bullet_types'] : '';
$efpe_accessibility  = (isset($view_options['efpe_accessibility']) && ($view_options['efpe_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';
$center_mode        = 'false';

if ('center' === $carousel_mode) {
	$center_mode = 'true';
}

?>
<!-- Markup Starts -->
<div id="efpe_wrapper-<?php echo esc_html($efpe_gl_id); ?>" class="<?php self::efpe_wrapper_classes($layout_preset, $efpe_gl_id, $pagination_type, $item_same_height_class); ?> <?php echo esc_html($carousel_mode); ?>" <?php self::wrapper_data($pagination_type, $pagination_type_mobile, $efpe_gl_id, $options, $layout_preset); ?> data-sid="<?php echo esc_html($efpe_gl_id); ?>">

	<?php EventfulForElementorLoopHtml::efpe_preloader($show_preloader); ?>
	<?php require EventfulForElementorFunctions::eventful_for_elementor_locate_template('filter-bar.php'); ?>
	<div class="eventful">
		<div id="ta-efpe-id-<?php echo esc_html($efpe_gl_id); ?>" class="swiper swiper-container ta-efpe-carousel <?php echo esc_html($carousel_nav_position . $spta_fade_class); ?>" dir="<?php echo esc_html($carousel_direction); ?>" 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_column_width); ?>, "items":<?php echo esc_html($column_lg_desktop); ?>, "spaceBetween":<?php echo esc_html($margin_between_post); ?>, "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); ?>, "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($row_lg_desktop); ?>, "desktop": <?php echo esc_html($row_desktop); ?>, "tablet": <?php echo esc_html($row_tablet); ?>, "mobile_landscape": <?php echo esc_html($row_mobile_landscape); ?>, "mobile": <?php echo esc_html($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($column_lg_desktop); ?>, "desktop": <?php echo esc_html($column_desktop); ?>, "tablet": <?php echo esc_html($column_tablet); ?>, "mobile_landscape": <?php echo esc_html($column_mobile_landscape); ?>, "mobile": <?php echo esc_html($column_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($efpe_accessibility); ?>", "paginationBulletMessage": "<?php echo esc_html($accessibility_pagination_bullet_text); ?>" }'>
			<div class="swiper-wrapper">
				<?php self::eventful_for_elementor_get_posts($options, $layout_preset, $event_content_sorter, $efpe_query, $efpe_gl_id, $efpe_settings); ?>
			</div>
			<?php
			if ('true' === $pagination && 'ticker' !== $carousel_mode) {
			?>
				<div class="efpe-pagination swiper-pagination <?php echo esc_html($bullet_types); ?>"></div>
			<?php } ?>
			<?php if ('true' === $navigation && 'ticker' !== $carousel_mode) { ?>
				<div class="efpe-button-next swiper-button-next <?php echo esc_html($carousel_nav_position); ?>"><i class="fa <?php echo esc_html($navigation_icons); ?>-right"></i></div>
				<div class="efpe-button-prev swiper-button-prev <?php echo esc_html($carousel_nav_position); ?>"><i class="fa <?php echo esc_html($navigation_icons); ?>-left"></i></div><?php } ?>
		</div>
	</div>
</div>