<?php
use MASCOTCOREEDUCACION\CPT\Gallery\CPT_Gallery;

/*
 * outputs mascot_core_educacion_widget_gallery widget.
 */
if( !function_exists( 'mascot_core_educacion_widget_gallery' ) ) {
	function mascot_core_educacion_widget_gallery( $args, $instance ) {
		echo wp_kses_post($args['before_widget']);

		if ( ! empty( $instance['title'] ) ) {
			echo wp_kses_post( $args['before_title'] . apply_filters( 'widget_title', $instance['title'] ) . $args['after_title'] );
		}

		//get gallery instance
		$new_cpt_class = CPT_Gallery::Instance();
		//default posts per page
		$posts_per_page = ( $instance['items_count'] == '' ) ? -1 : $instance['items_count'];
		//query args
		$query_args = array(
			'post_type' => $new_cpt_class->ptKey,
			'orderby' => $instance['order_by'],
			'order' => $instance['order'],
			'posts_per_page' => $posts_per_page,
		);

		$the_query = new \WP_Query( $query_args );
		$instance['the_query'] = $the_query;


		educacion_mascot_wp_enqueue_script_lightgallery();
		//Produce HTML version by using the parameters (filename, variation, folder name, parameters, widget_ob_start)
		$html = educacion_mascot_get_widget_template_part( 'gallery', null, 'gallery/tpl', $instance, false );

		echo wp_kses_post($args['after_widget']);
	}
}