jQuery(document).ready(function(){

	jQuery(".wpic_select2").each(function(){
		jQuery(this).select2();
	});

	jQuery('.wpic-color').wpColorPicker();

	jQuery('.wpic-template-items').slick({
	  infinite: true,
	  slidesToShow: 1,
	  slidesToScroll: 1,
	  lazyLoad: 'ondemand',

	});

	var id ='singlecolor';
	if(wcrr_ajax_obj.active_template){
		 id = wcrr_ajax_obj.active_template;
	}
	var $slide = jQuery(".wpic-template-items [data-tempname=" + id + "]");
	var slideIndex = $slide.data("slick-index");
	jQuery(".wpic-template-items").slick("goTo", slideIndex);
	$slide.addClass('check');


jQuery(document).on('click','.wpic-template-items .wpic-cd-4',function(){
	if(confirm('Do you want to switch Review Template?')){
		jQuery(this).addClass('check');
		var tempname = jQuery(this).data('tempname');

		var data = {ajax_handler:'wcrr_update_template_name',nonce:wcrr_ajax_obj.nonce,action:'wcrr_ajax_call',tempname:tempname};
		jQuery.ajax({
			url:wcrr_ajax_obj.ajax_url,
			method:'POST',
			data:data,
			dataType:'JSON',
			success:function(response){
				jQuery("#review_template").val(tempname);
				console.log(response);
				//location.reload();
			},
			error:function(error){
				console.log(error);
			}

		});

	}

});
	




});