<?php

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

function shrk_sc_ps_slider($atts, $content = NULL) {
	$atts = shortcode_atts( array(
		'section_id'    => false,
		'slider_id'                => null,
		'swiper_mode'              => 'horizontal',
		'swiper_spv'               => '1', //Slides per view
		'swiper_effect'            => 'slide',
		'swiper_speed'             => '5000',
		'swiper_animation_speed'   => '300',
		'swiper_autoplay'          => 'no',
		'swiper_loop'              => 'no',
		'show_scrollbar'           => 'no',
		'hide_pagination'          => 'no',
		'slides_grid_width'        => '12', // 12 = one per slide
		'space_between_slides'     => '0',
		'partial_view'             => 'no',
		'partial_max_width'        => '80%',
		'slider_bg_color_inline'   => '',
		'swiper_controls_colors'   => 'light',
		'swiper_controls_transp'   => 'no',
		'arrows_hidden_xs'         => 'no',
		'pagination_only_xs'       => 'no',
		'swiper_breakpoints'       => 'disable',
	), $atts );

	$slider_id = !empty( $atts['slider_id'] ) ? esc_attr( $atts['slider_id'] ) : false;
	if ( empty($content) ) { $content = '<h3>' . esc_html__('Your Sections Slider has no sections in it!', 'dvl-uxshop-shortcodes') . '</h3>'; }

	if ( !function_exists( 'shrk_sc_swiper_get_atts' ) ) {
		return '<div>' . esc_html__('Your theme does not support the pagesections slider.', 'dvl-uxshop-shortcodes') . '</div>';
	}

	ob_start();

	echo '<div ' . ( $slider_id ? 'id="' . esc_attr( $slider_id ) . '"' : '' ) . ' ' . shrk_sc_swiper_get_atts( $atts, array('shrk-swiper-container', 'sections-slider') ) . '>';
	echo '<div class="sections-slider-inner">';
	echo do_shortcode( $content );
	echo '</div>';
	echo '</div>';

	return ob_get_clean();
}

add_action( 'init', function () {
	add_shortcode('shrk_section_slider', 'shrk_sc_ps_slider');
});

add_filter( 'shrk_filter_vc_mappings', function ( $shrk_vc_shortcodes ) {

	$shrk_vc_shortcodes["shrk_section_slider"] =  array(
		"name" => esc_html__("Page Sections Slider", 'dvl-uxshop-shortcodes'),
		"base" => "shrk_section_slider",
		"as_parent" => array('only' => 'shrk_section'), // Use only|except attributes to limit child shortcodes (separate multiple values with comma)
		"content_element" => true,
		"icon" => "icon-wpb-shrk",
		"category" => esc_html__('Theme Specific', 'dvl-uxshop-shortcodes'),
		"show_settings_on_create" => false,
		/**
		 * Set the width of the Sections Slider by setting the width of the row it is in.
		 * Set the height of each of the slides explicitly in that section's options.
		 * Dont set full to width to rows inside the section
		 * Dont set full height to the row containing the section slider.
		 */
		"params" => array(
			array(
				"type" => "textfield",
				"class" => "hidden",
				"param_name" => "slider_id",
				"value" => uniqid('swiper-'),
			),
			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",
				),
			),
			array(
				"type" => 'colorpicker',
				"heading" => esc_html__("Set slider background color.", 'dvl-uxshop-shortcodes'),
				"param_name" => "slider_bg_color_inline",
			),
			array(
				"type" => "dropdown",
				"heading" => esc_html__("Slider controls theme", 'dvl-uxshop-shortcodes'),
				"param_name" => "swiper_controls_colors",
				"value" => array(
					esc_html__("Light", 'dvl-uxshop-shortcodes')     => "light",
					esc_html__("Dark", 'dvl-uxshop-shortcodes')      => "dark",
				),
			),
			array(
				"type" => 'checkbox',
				"heading" => esc_html__("Transparent arrows", 'dvl-uxshop-shortcodes'),
				"param_name" => "swiper_controls_transp",
				"value" => Array(esc_html__("Yes", 'dvl-uxshop-shortcodes') => 'yes')
				),
			array(
				"type" => 'checkbox',
				"heading" => esc_html__("Slider autoplay", 'dvl-uxshop-shortcodes'),
				"param_name" => "swiper_autoplay",
				"value" => Array(esc_html__("Yes", 'dvl-uxshop-shortcodes') => 'yes')
				),
			array(
				"type" => "textfield",
				"heading" => esc_html__("Autoplay delay (in milliseconds)", 'dvl-uxshop-shortcodes'),
				"param_name" => "swiper_speed",
				"value" => '7000',
				"description" => esc_html__("Set the number of milliseconds to wait before showing the next slide.", 'dvl-uxshop-shortcodes'),
				"dependency" => Array('element' => "swiper_autoplay", 'value' => array('yes')),
				),
			array(
				"type" => "textfield",
				"heading" => esc_html__("Animation speed (in milliseconds)", 'dvl-uxshop-shortcodes'),
				"param_name" => "swiper_animation_speed",
				"value" => '300',
				"description" => esc_html__("Set the speed for the transition between slides.", 'dvl-uxshop-shortcodes')
				),
			array(
				"type" => 'checkbox',
				"heading" => esc_html__("Loop Slider", 'dvl-uxshop-shortcodes'),
				"param_name" => "swiper_loop",
				"value" => Array(esc_html__("Yes", 'dvl-uxshop-shortcodes') => 'yes')
				),
			array(
				"type" => 'checkbox',
				"heading" => esc_html__("Show scrollbar", 'dvl-uxshop-shortcodes'),
				"param_name" => "show_scrollbar",
				"value" => Array(esc_html__("Yes", 'dvl-uxshop-shortcodes') => 'yes')
				),
			array(
				"type" => 'dropdown',
				"heading" => esc_html__("Hide pagination", 'dvl-uxshop-shortcodes'),
				"param_name" => "hide_pagination",
				"value" => array(
						esc_html__("Yes", 'dvl-uxshop-shortcodes')     => "yes",
						esc_html__("No", 'dvl-uxshop-shortcodes')      => "no",
					),
				"save_always" => true
				),
			array(
				"type" => 'checkbox',
				"heading" => esc_html__("Hide arrows on mobile", 'dvl-uxshop-shortcodes'),
				"param_name" => "arrows_hidden_xs",
				"value" => Array(esc_html__("Yes", 'dvl-uxshop-shortcodes') => 'yes')
				),
			array(
				"type" => 'checkbox',
				"heading" => esc_html__("Hide pagination on desktop", 'dvl-uxshop-shortcodes'),
				"param_name" => "pagination_only_xs",
				"value" => Array(esc_html__("Yes", 'dvl-uxshop-shortcodes') => 'yes')
				),
		),
		'js_view' => 'VcColumnView',
	);

	return $shrk_vc_shortcodes;
} );

?>