<?php
namespace MASCOTCOREEDUCACION\CPT\Gallery\Shortcodes;

use MASCOTCOREEDUCACION\Lib;
use MASCOTCOREEDUCACION\CPT\Gallery\CPT_Gallery;

/**
 * class SC_Gallery
 * @package MASCOTCOREEDUCACION\CPT\Gallery\Shortcodes;
 */
class SC_Gallery implements Lib\Mascot_Core_Educacion_Interface_PTShortcodes {
	
	/**
	 * @var string
	 */
	private $base;

	/**
	 * construct
	 */
	public function __construct() {
		if ( class_exists( 'ReduxFramework' ) ) {
			if( ! mascot_core_educacion_get_redux_option( 'cpt-settings-gallery-enable', true ) ) {
				return;
			}
		}
		$this->base = 'tmvc_gallery';
		add_action('init', array($this, 'vcMap'), 998);
	}

	/**
	 * Returns base for shortcode
	 * @return string
	 */
	public function getBase() {
		return $this->base;
	}

	/**
	 * Maps shortcode to Visual Composer
	 *
	 * @see vc_map()
	 */
	public function vcMap() {
		if(function_exists('vc_map')) {
			$group_content_options = esc_html__( 'Content', 'mascot-core' );
			$group_filter_options = esc_html__( 'Filter', 'mascot-core' );
			$group_carousel_options = esc_html__( 'Carousel', 'mascot-core' );
			$group_query_options = esc_html__( 'Query', 'mascot-core' );
			$group_lightbox_options = esc_html__( 'Lightbox', 'mascot-core' );
			$group_loadmore_button_options = esc_html__( 'Loadmore Button', 'mascot-core' );
			$new_cpt_class = CPT_Gallery::Instance();
			$categories_array = mascot_core_educacion_category_list_array_for_vc( $new_cpt_class->ptTaxKey );

			$orderby_parameters_list = mascot_core_educacion_orderby_parameters_list();


			$vc_map = array(
				'name'		=> esc_html__( 'Gallery', 'mascot-core' ),
				'base'		=>$this->base,
				'category'	=> 'by TM',
				'description' => esc_html__( 'Gallery Grid/Carousel', 'mascot-core' ),
				'icon'		=> 'mascot-vc-icons vc-icon-gallery',
				'allowed_container_element' => 'vc_row',
				'params'	=>array(
					array(
						'type'			=> 'textfield',
						"heading"		=> esc_html__( "Custom CSS class", 'mascot-core' ),
						"param_name"	=> "custom_css_class",
						"description"	=> esc_html__( 'To style particular content element.', 'mascot-core' ),
					),
					array(
						'type'			=> 'dropdown',
						"heading"		=> esc_html__( "Design Style", 'mascot-core' ),
						"param_name"	=> "design_style",
						"description"	=> "",
						'value'			=> array(
							esc_html__( 'Style 1 - Default', 'mascot-core' )	=> 'gallery-style1-simple',
							esc_html__( 'Style 2 - Classic', 'mascot-core' )	=> 'gallery-style2-classic',
							esc_html__( 'Style 3 - Modern', 'mascot-core' )		=> 'gallery-style3-modern',
							esc_html__( 'Style 4 - Current Theme', 'mascot-core' )	=> 'gallery-style4-current-theme',
						),
						'save_always'   => true,
						'admin_label'   => true,
					),
					array(
						'type'			=> 'dropdown',
						"heading"		=> esc_html__( "Display Type", 'mascot-core' ),
						"param_name"	=> "display_type",
						"description"	=> "",
						'value'			=> array(
							esc_html__( 'Grid', 'mascot-core' )		=> 'grid',
							esc_html__( 'Masonry', 'mascot-core' )	=> 'masonry',
							esc_html__( 'Carousel', 'mascot-core' )	=> 'carousel'
						),
						'save_always'   => true,
						'admin_label'   => true,
					),
					array(
						'type'			=> 'dropdown',
						"heading"		=> esc_html__( "Columns Layout", 'mascot-core' ),
						"param_name"	=> "columns",
						"description"	=> esc_html__( 'Define Columns Layout for Grid/Carousel.', 'mascot-core' ),
						'value'			=> array(
							'1'  =>  '1',
							'2'  =>  '2',
							'3'  =>  '3',
							'4'  =>  '4',
							'5'  =>  '5',
							'6'  =>  '6',
							'7'  =>  '7',
							'8'  =>  '8',
							'9'  =>  '9',
							'10'  =>  '10',
						),
						'std'			=> 3,
						'admin_label'   => true,
					),

					//Thumbnail Options
					array(
						'type'			=> 'dropdown',
						"heading"		=> esc_html__( "Featured Image Size", 'mascot-core' ),
						"param_name"	=> "featured_image_size",
						'description'   => '',
						'value'			=> mascot_core_educacion_get_available_image_sizes_for_vc(),
						'std'			=> 'post-thumbnail',
					),
					array(
						'type'			=> 'dropdown',
						"heading"		=> esc_html__( "Use Predefined Image Size in Masonry Mode", 'mascot-core' ),
						"param_name"	=> "use_masonry_tiles_featured_image_size",
						"description"	=> esc_html__( 'If you choose yes, then "Featured Image Size" will not work.', 'mascot-core' ),
						'value'			=> array(
							esc_html__( 'Yes', 'mascot-core' )	=> 'true',
							esc_html__( 'No', 'mascot-core' )	=> 'false',
						),
						'dependency'	=> array('element' => 'display_type', 'value' => array('masonry') ),
					),



					//Carousel Options
					mascot_core_educacion_get_owl_carousel_arraylist( 1, $group_carousel_options, '', array('element' => 'display_type', 'value' => array( 'carousel' ) ) ),
					mascot_core_educacion_get_owl_carousel_arraylist( 2, $group_carousel_options, '', array('element' => 'display_type', 'value' => array( 'carousel' ) ) ),
					mascot_core_educacion_get_owl_carousel_arraylist( 3, $group_carousel_options, '', array('element' => 'display_type', 'value' => array( 'carousel' ) ) ),
					mascot_core_educacion_get_owl_carousel_arraylist( 4, $group_carousel_options, '', array('element' => 'display_type', 'value' => array( 'carousel' ) ) ),
					mascot_core_educacion_get_owl_carousel_arraylist( 5, $group_carousel_options, '', array('element' => 'display_type', 'value' => array( 'carousel' ) ) ),
					mascot_core_educacion_get_owl_carousel_arraylist( 6, $group_carousel_options, '', array('element' => 'display_type', 'value' => array( 'carousel' ) ) ),
					mascot_core_educacion_get_owl_carousel_arraylist( 7, $group_carousel_options, '', array('element' => 'display_type', 'value' => array( 'carousel' ) ) ),
					mascot_core_educacion_get_owl_carousel_arraylist( 8, $group_carousel_options, '', array('element' => 'display_type', 'value' => array( 'carousel' ) ) ),
					mascot_core_educacion_get_owl_carousel_arraylist( 9, $group_carousel_options, '', array('element' => 'display_type', 'value' => array( 'carousel' ) ) ),
					mascot_core_educacion_get_owl_carousel_arraylist( 10, $group_carousel_options, '', array('element' => 'display_type', 'value' => array( 'carousel' ) ) ),
					mascot_core_educacion_get_owl_carousel_arraylist( 11, $group_carousel_options, '', array('element' => 'display_type', 'value' => array( 'carousel' ) ) ),
					mascot_core_educacion_get_owl_carousel_arraylist( 12, $group_carousel_options, '', array('element' => 'display_type', 'value' => array( 'carousel' ) ) ),


					//Query Options
					array(
						'type'			=> 'textfield',
						"heading"		=> esc_html__( "Number of Items to Query from Database", 'mascot-core' ),
						"param_name"	=> "total_items",
						"description"	=> esc_html__( 'How many items do you wish to show? Put -1 to show all. Default 3', 'mascot-core' ),
						'value'			=> 3,
						'admin_label'	=> true,
						'group'			=> $group_query_options
					),
					array(
						'type'			=> 'checkbox',
						"heading"		=> esc_html__( "Category", 'mascot-core' ),
						"param_name"	=> "selected_category",
						"description"	=> esc_html__( 'Choose a category to pull gallery from.', 'mascot-core' ),
						'value'			=> $categories_array,
						'group'			=> $group_query_options
					),
					array(
						'type'			=> 'dropdown',
						"heading"		=> esc_html__( "Order By", 'mascot-core' ),
						"param_name"	=> "order_by",
						"description"	=> esc_html__( 'Select how to sort retrieved posts.', 'mascot-core' ),
						'value'			=> $orderby_parameters_list,
						'std'			=> $orderby_parameters_list[ 'Date' ],
						'group'			=> $group_query_options
					),
					array(
						'type'			=> 'dropdown',
						"heading"		=> esc_html__( "Order", 'mascot-core' ),
						"param_name"	=> "order",
						"description"	=> esc_html__( 'Descending or Ascending order.', 'mascot-core' ),
						'value'			=> array(
							esc_html__( 'Descending', 'mascot-core' )	=> 'DESC',
							esc_html__( 'Ascending', 'mascot-core' )	=> 'ASC',
						),
						'group'			=> $group_query_options
					),



					//Content Options
					
					//Category Filter
					mascot_core_educacion_get_cat_filter_arraylist( 1, $group_content_options, array('element' => 'display_type', 'value' => array('grid', 'masonry', 'carousel') ) ),
					mascot_core_educacion_get_cat_filter_arraylist( 2, $group_content_options ),
					mascot_core_educacion_get_cat_filter_arraylist( 3, $group_content_options ),
					mascot_core_educacion_get_cat_filter_arraylist( 4, $group_content_options ),


					array(
						'type'			=> 'dropdown',
						"heading"		=> esc_html__( "Gutter", 'mascot-core' ),
						"param_name"	=> "gutter",
						'value'			=> mascot_core_educacion_portfolio_gutter_list(),
						'save_always'   => true,
						'admin_label'   => true,
						'dependency'	=> array('element' => 'display_type', 'value' => array('grid', 'masonry')),
						'group'			=> $group_content_options
					),
					array(
						'type'			=> 'dropdown',
						"heading"		=> esc_html__( "Overlay Color on Image", 'mascot-core' ),
						"param_name"	=> "gallery_overlay_color_on_image",
						"description"	=> "",
						'value'			=> array(
							'Theme Color 1 Ovedrlay'	=> 'shade-theme-colored1',
							'Theme Color 2 Ovedrlay'	=> 'shade-theme-colored2',
							'Black Ovedrlay'			=> 'shade-black',
							'White Ovedrlay'			=> 'shade-white',
						),
						'save_always'   => true,
						'group'			=> $group_content_options
					),
					array(
						'type'			=> 'dropdown',
						"heading"		=> esc_html__( "Add Gradient Effect on Image", 'mascot-core' ),
						"param_name"	=> "show_gradient_effect_on_image",
						'description'   => '',
						'value'			=> array(
							esc_html__( 'No', 'mascot-core' )	=> 'false',
							esc_html__( 'Yes', 'mascot-core' )	=> 'true',
						),
						'std'			=> 'false',
						'save_always'   => true,
						'group'			=> $group_content_options
					),
					array(
						'type'			=> 'dropdown',
						"heading"		=> esc_html__( "Show Title", 'mascot-core' ),
						"param_name"	=> "show_gallery_title",
						'description'   => '',
						'value'			=> array(
							esc_html__( 'Yes', 'mascot-core' )	=> 'true',
							esc_html__( 'No', 'mascot-core' )	=> 'false'
						),
						'std'			=> 'true',
						'group'			=> $group_content_options
					),
					array(
						'type'			=> 'dropdown',
						"heading"		=> esc_html__( "Show Date", 'mascot-core' ),
						"param_name"	=> "show_gallery_date",
						'description'   => '',
						'value'			=> array(
							esc_html__( 'No', 'mascot-core' )	=> 'false',
							esc_html__( 'Yes', 'mascot-core' )	=> 'true',
						),
						'std'			=> 'false',
						'group'			=> $group_content_options
					),
					array(
						'type'			=> 'dropdown',
						"heading"		=> esc_html__( "Show Category", 'mascot-core' ),
						"param_name"	=> "show_selected_category",
						'description'   => '',
						'value'			=> array(
							esc_html__( 'No', 'mascot-core' )	=> 'false',
							esc_html__( 'Yes', 'mascot-core' )	=> 'true',
						),
						'std'			=> 'false',
						'group'			=> $group_content_options
					),
					array(
						'type'			=> 'dropdown',
						"heading"		=> esc_html__( "Show Description", 'mascot-core' ),
						"param_name"	=> "show_gallery_description",
						'description'   => '',
						'value'			=> array(
							esc_html__( 'No', 'mascot-core' )	=> 'false',
							esc_html__( 'Yes', 'mascot-core' )	=> 'true',
						),
						'std'			=> 'false',
						'group'			=> $group_content_options
					),


					//lightbox options
					array(
						'type'			=> 'dropdown',
						"heading"		=> esc_html__( "Lightbox Scroll Through", 'mascot-core' ),
						"param_name"	=> "lightbox_scroll_through",
						'value'			=> array(
							esc_html__( 'Scroll Through Own Gallery Images', 'mascot-core' )	=> 'scroll-gallery-images',
							esc_html__( 'Scroll Through Only Featured Images', 'mascot-core' )	=> 'scroll-featured-images',
						),
						'group'			=> $group_lightbox_options
					),
					array(
						'type'			=> 'dropdown',
						"heading"		=> esc_html__( "Show Link(Details Page) Icon on Hover", 'mascot-core' ),
						"param_name"	=> "show_link_icon_on_hover",
						'description'   => '',
						'value'			=> array(
							esc_html__( 'No', 'mascot-core' )	=> 'false',
							esc_html__( 'Yes', 'mascot-core' )	=> 'true',
						),
						'std'			=> 'true',
						'save_always'   => true,
						'group'			=> $group_lightbox_options
					),

					//Loadmore Button options
					mascot_core_educacion_get_viewdetails_button_arraylist( 1, $group_loadmore_button_options,  esc_html__( "Load More", 'mascot-core' ), 'loadmore_', 'false' ),
					mascot_core_educacion_get_viewdetails_button_arraylist( 2, $group_loadmore_button_options,  esc_html__( "Load More", 'mascot-core' ), 'loadmore_', 'false' ),
					$array = array(
						'type'			=> 'textfield',
						"heading"		=> esc_html__( "Loading Text", 'mascot-core' ),
						"param_name"	=> "loadmore_button_loading_text",
						'std'			=> esc_html__( "Loading...", 'mascot-core' ),
						'save_always'   => true,
						'group'			=> $group_loadmore_button_options
					),
					mascot_core_educacion_get_button_arraylist( 1, $group_loadmore_button_options, 'loadmore_' ),
					mascot_core_educacion_get_button_arraylist( 2, $group_loadmore_button_options, 'loadmore_' ),
					mascot_core_educacion_get_button_arraylist( 3, $group_loadmore_button_options, 'loadmore_' ),
					mascot_core_educacion_get_button_arraylist( 4, $group_loadmore_button_options, 'loadmore_' ),
					mascot_core_educacion_get_button_arraylist( 5, $group_loadmore_button_options, 'loadmore_' ),
					mascot_core_educacion_get_button_arraylist( 6, $group_loadmore_button_options, 'loadmore_' ),
					mascot_core_educacion_get_button_arraylist( 7, $group_loadmore_button_options, 'loadmore_' ),
					mascot_core_educacion_get_button_arraylist( 8, $group_loadmore_button_options, 'loadmore_' ),
					mascot_core_educacion_get_button_arraylist( 9, $group_loadmore_button_options, 'loadmore_' ),




				)
			);
			vc_map( $vc_map );

			//Modify vc_map from themes
			if( function_exists('mascot_core_educacion_cpt_sc_gallery_vc_map_modifier') ) {
				mascot_core_educacion_cpt_sc_gallery_vc_map_modifier( $this->base );
			}
		}
	}

	/**
	 * Renders shortcodes HTML
	 *
	 * @param $attr array of shortcode params
	 * @param $content string shortcode content
	 * @return string
	 */
	public function render( $attr, $content = null ) {
		if ( class_exists( 'ReduxFramework' ) ) {
			if( ! mascot_core_educacion_get_redux_option( 'cpt-settings-gallery-enable', true ) ) {
				return;
			}
		}

		//Render Shortcode from themes
		if( function_exists('mascot_core_educacion_cpt_sc_gallery_render') && function_exists('vc_map') ) {
			return mascot_core_educacion_cpt_sc_gallery_render( $attr, $content, CPT_Gallery::Instance() );
		}
		
	}
}