<?php

if(!function_exists('mascot_core_educacion_cpt_sc_clients_vc_map_modifier')) {
	/**
	 * Shortcodes vc_map modifier
	 */
	function mascot_core_educacion_cpt_sc_clients_vc_map_modifier( $shortcode_base ) {
		//vc_remove_param( $shortcode_base, "display_type" );
		//vc_add_param( $shortcode_base, $attributes );
		//vc_add_params( $shortcode_base, $attributes );
	}
}



if(!function_exists('mascot_core_educacion_cpt_sc_clients_render')) {
	/**
	 * Renders shortcodes HTML
	 */
	function mascot_core_educacion_cpt_sc_clients_render( $attr, $content = null, $class_instance ) {

		$new_cpt_class = $class_instance;
		$args = array(
			'custom_css_class' => '',
			'display_type' => '',
			'columns' => '6',
			'columns_grid' => '6',
			'hover_animation_type' => 'clients-animation-grayscale',

			'show_navigation' => 'true',
			'show_bullets' => 'true',
			'bullets_skin' => 'owl-dots-light-skin',
			'bullets_alignment' => 'owl-dots-center',
			'carousel_autoplay' => 'true',
			'carousel_loop' => 'true',
			'animation_speed' => '6000',
			'smart_speed' => '2000',
			'margin' => '30',
			'stagepadding' => '0',
			'laptop' => '',
			'tablet' => '',

			'total_items' => '4',
			'selected_category' => '',
			'order_by' => 'date',
			'order' => 'DESC',

			'show_client_name' => 'false',
			'show_client_description'	=> 'false',
			'show_client_logo' => 'true',
			'link_client_url' => 'true',
			'open_links_in' => '_blank',
		);
		$params = shortcode_atts($args, $attr);

		//query args
		$args = array(
			'post_type' => $new_cpt_class->ptKey,
			'orderby' => $params['order_by'],
			'order' => $params['order'],
			'posts_per_page' => $params['total_items'],
		);

		//if category selected
		if( ! empty( $params['selected_category'] ) ) {
			$args['tax_query'] = array(
				array(
					'taxonomy' => $new_cpt_class->ptTaxKey,
					'field'	=> 'slug',
					'terms'	=> explode(',', $params['selected_category']),
				)
			);
		}

		//if order by client_author_name selected
		if( $params['order_by'] == 'client_name' ) {
			$args['meta_key'] = 'educacion_mascot_' . 'client_name';
			$args['orderby']  = 'meta_value';
		}

		$the_query = new \WP_Query( $args );
		$params['the_query'] = $the_query;

		//classes
		$classes = array();
		if( $params['display_type'] == 'carousel' ) {
			$classes[] = $params['bullets_skin'];
			$classes[] = $params['bullets_alignment'];
		}
		$classes[] = $params['custom_css_class'];
		$classes[] = $params['hover_animation_type'];
		$params['classes'] = $classes;
		
		//Owl Carousel Data
		$params['owl_carousel_data_info'] = educacion_mascot_prepare_owlcarousel_data_from_params( $params );

		//Produce HTML version by using the parameters (filename, variation, folder name, parameters, shortcode_ob_start)
		$html = educacion_mascot_get_cpt_template_part( 'clients', $params['display_type'], 'clients/shortcodes/tpl', $params, true );
		
		return $html;
	}
}