<?php

if(!function_exists('mascot_core_educacion_sc_wc_products_vc_map_modifier')) {
	/**
	 * Shortcodes vc_map modifier
	 */
	function mascot_core_educacion_sc_wc_products_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_sc_wc_products_render')) {
	/**
	 * Renders shortcodes HTML
	 */
	function mascot_core_educacion_sc_wc_products_render( $attr, $content = null ) {
		
		$args = array(
			'custom_css_class' => '',
			'display_type' => '',
			'columns' => '4',

			'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',
			'category' => '',
			'order_by' => 'date',
			'order' => 'DESC',


			'show_thumb' => 'true',
			'feature_thumb_image_size' => 'post-thumbnail',


			//cat filter
			'show_cat_filter' => 'false',
			'cat_filter_style' => '',
			'cat_filter_alignment' => '',
			'cat_filter_theme_colored' => '',
		);
		$params = shortcode_atts($args, $attr);

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

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

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


		$params['holder_id'] = educacion_mascot_get_isotope_holder_ID('wc-product');

		//classes
		$classes = array();
		if( $params['display_type'] == 'carousel' ) {
			$classes[] = $params['bullets_skin'];
			$classes[] = $params['bullets_alignment'];
		}
		$classes[] = $params['custom_css_class'];
		$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_shortcode_template_part( 'wc-products', $params['display_type'], 'wc-products/tpl', $params, true );
		
		return $html;
	}
}