<?php
/**
 * The template for adding Featured Grid Content Options in Customizer
 *
 * @package Gridalicious Catch Themes
 * @subpackage Gridalicious
 * @since Gridalicious 1.0
 */

if ( ! defined( 'GRIDALICIOUS_THEME_VERSION' ) ) {
	header( 'Status: 403 Forbidden' );
	header( 'HTTP/1.1 403 Forbidden' );
	exit();
}
	// Featured Grid Content
	if ( 4.3 > get_bloginfo( 'version' ) ) {
		$wp_customize->add_panel( 'gridalicious_featured_grid_content', array(
		    'capability'     => 'edit_theme_options',
		    'description'    => __( 'Featured Grid Content Options', 'gridalicious-pro' ),
		    'priority'       => 500,
			'title'    		 => __( 'Featured Grid Content', 'gridalicious-pro' ),
		) );

		$wp_customize->add_section( 'gridalicious_featured_grid_content', array(
			'panel'			=> 'gridalicious_featured_grid_content',
			'priority'		=> 1,
			'title'			=> __( 'Featured Grid Content Options', 'gridalicious-pro' ),
		) );
	}
	else {
		$wp_customize->add_section( 'gridalicious_featured_grid_content', array(
			'priority'		=> 500,
			'title'			=> __( 'Featured Grid Content', 'gridalicious-pro' ),
		) );
	}

	$wp_customize->add_setting( 'gridalicious_theme_options[featured_grid_content_option]', array(
		'capability'		=> 'edit_theme_options',
		'default'			=> $defaults['featured_grid_content_option'],
		'sanitize_callback'	=> 'gridalicious_sanitize_select'
	) );

	$wp_customize->add_control( 'gridalicious_theme_options[featured_grid_content_option]', array(
		'choices'   => gridalicious_featured_grid_content_options(),
		'label'    	=> __( 'Enable Grid Content on', 'gridalicious-pro' ),
		'priority'	=> '1.1',
		'section'  	=> 'gridalicious_featured_grid_content',
		'settings' 	=> 'gridalicious_theme_options[featured_grid_content_option]',
		'type'    	=> 'select',
	) );

	$wp_customize->add_setting( 'gridalicious_theme_options[featured_grid_content_type]', array(
		'capability'		=> 'edit_theme_options',
		'default'			=> $defaults['featured_grid_content_type'],
		'sanitize_callback'	=> 'gridalicious_sanitize_select',
	) );

	$wp_customize->add_control( 'gridalicious_theme_options[featured_grid_content_type]', array(
		'active_callback'	=> 'gridalicious_is_grid_content_active',
		'choices'  	=> gridalicious_featured_grid_content_types(),
		'label'    	=> __( 'Select Grid Content Type', 'gridalicious-pro' ),
		'priority'	=> '2.1.3',
		'section'  	=> 'gridalicious_featured_grid_content',
		'settings' 	=> 'gridalicious_theme_options[featured_grid_content_type]',
		'type'	  	=> 'select',
	) );

	$wp_customize->add_setting( 'gridalicious_theme_options[featured_grid_content_number]', array(
		'capability'		=> 'edit_theme_options',
		'default'			=> $defaults['featured_grid_content_number'],
		'sanitize_callback'	=> 'gridalicious_sanitize_number_range',
	) );

	$wp_customize->add_setting( 'gridalicious_theme_options[featured_grid_content_layout]', array(
		'capability'		=> 'edit_theme_options',
		'default'			=> $defaults['featured_grid_content_layout'],
		'sanitize_callback'	=> 'gridalicious_sanitize_select'
	) );

	$wp_customize->add_control( 'gridalicious_theme_options[featured_grid_content_layout]', array(
		'active_callback'	=> 'gridalicious_is_demo_grid_content_inactive',
		'choices'   => array(
			'layout-one'   => esc_html__( '1 column', 'gridalicious-pro' ),
			'layout-two'   => esc_html__( '2 columns', 'gridalicious-pro' ),
			'layout-three' => esc_html__( '3 columns', 'gridalicious-pro' ),
		),
		'label'    	=> __( 'Layout', 'gridalicious-pro' ),
		'priority'	=> '1.2',
		'section'  	=> 'gridalicious_featured_grid_content',
		'settings' 	=> 'gridalicious_theme_options[featured_grid_content_layout]',
		'type'    	=> 'select',
	) );



	$wp_customize->add_control( 'gridalicious_theme_options[featured_grid_content_number]' , array(
		'active_callback'	=> 'gridalicious_is_demo_grid_content_inactive',
		'description'	=> __( 'Save and refresh the page if No. of Grid Content is changed (Max no of grid content is 30). No. of Grid Content in set as a multiple of 3', 'gridalicious-pro' ),
		'input_attrs' 	=> array(
            'style' => 'width: 45px;',
            'min'   => 1,
        	),
		'label'    		=> __( 'No of Grid Content', 'gridalicious-pro' ),
		'priority'		=> '2.1.4',
		'section'  		=> 'gridalicious_featured_grid_content',
		'settings' 		=> 'gridalicious_theme_options[featured_grid_content_number]',
		'type'	   		=> 'number',
		)
	);

	$wp_customize->add_setting( 'gridalicious_theme_options[exclude_grid_content_post]', array(
		'capability'		=> 'edit_theme_options',
		'default'			=> $defaults['exclude_grid_content_post'],
		'sanitize_callback'	=> 'gridalicious_sanitize_checkbox',
	) );

	$wp_customize->add_control(  'gridalicious_theme_options[exclude_grid_content_post]', array(
		'active_callback'	=> 'gridalicious_is_post_grid_content_active',
		'label'		=> __( 'Check to exclude Grid Content post from Homepage posts', 'gridalicious-pro' ),
		'priority'	=> '2.1.4.1',
		'section'   => 'gridalicious_featured_grid_content',
		'settings'  => 'gridalicious_theme_options[exclude_grid_content_post]',
		'type'		=> 'checkbox',
	) );

	$wp_customize->add_setting( 'gridalicious_theme_options[featured_grid_content_select_category]', array(
		'capability'		=> 'edit_theme_options',
		'sanitize_callback'	=> 'gridalicious_sanitize_category_list',
	) );

	$wp_customize->add_control( new Gridalicious_Customize_Dropdown_Categories_Control( $wp_customize, 'gridalicious_theme_options[featured_grid_content_select_category]', array(
        'active_callback'	=> 'gridalicious_is_category_grid_content_active',
        'label'   	=> __('Select Categories', 'gridalicious-pro' ),
        'name' 		=> 'gridalicious_theme_options[featured_grid_content_select_category]',
		'priority'	=> '10',
        'section'  	=> 'gridalicious_featured_grid_content',
        'settings' 	=> 'gridalicious_theme_options[featured_grid_content_select_category]',
        'type'     	=> 'dropdown-categories',
    ) ) );

	$priority	=	'11';

	//loop for featured post grid contents
	for ( $i=1; $i <=  $options['featured_grid_content_number'] ; $i++ ) {
		$wp_customize->add_setting( 'gridalicious_theme_options[featured_grid_content_post_'. $i .']', array(
			'capability'		=> 'edit_theme_options',
			'sanitize_callback'	=> 'gridalicious_sanitize_page',
		) );

		$wp_customize->add_control( 'gridalicious_theme_options[featured_grid_content_post_'. $i .']', array(
		'active_callback'	=> 'gridalicious_is_post_grid_content_active',
			'input_attrs' => array(
        		'style' => 'width: 80px;'
    		),
			'label'    	=> __( 'Featured Post', 'gridalicious-pro' ) . ' # ' . $i ,
			'priority'	=>  '3' . $i,
			'section'  	=> 'gridalicious_featured_grid_content',
			'settings' 	=> 'gridalicious_theme_options[featured_grid_content_post_'. $i .']',
			'type'	   	=> 'text',
			)
		);

		$wp_customize->add_setting( 'gridalicious_theme_options[featured_grid_content_page_'. $i .']', array(
			'capability'		=> 'edit_theme_options',
			'sanitize_callback'	=> 'gridalicious_sanitize_page',
		) );

		$wp_customize->add_control( 'gridalicious_theme_options[featured_grid_content_page_'. $i .']', array(
			'active_callback'	=> 'gridalicious_is_page_grid_content_active',
			'label'    	=> __( 'Featured Page', 'gridalicious-pro' ) . ' # ' . $i ,
			'priority'	=> '4' . $i,
			'section'  	=> 'gridalicious_featured_grid_content',
			'settings' 	=> 'gridalicious_theme_options[featured_grid_content_page_'. $i .']',
			'type'	   	=> 'dropdown-pages',
		) );

		if ( $i > 9 ) // use this condition to make sure 10 comes after 9 priority wise
			$priority++;

		$wp_customize->add_setting( 'gridalicious_theme_options[featured_grid_content_note_'. $i .']', array(
			'capability'		=> 'edit_theme_options',
			'sanitize_callback'	=> 'sanitize_text_field',
		) );

		$wp_customize->add_control( new Gridalicious_Note_Control( $wp_customize, 'gridalicious_theme_options[featured_grid_content_note_'. $i .']', array(
			'active_callback'	=> 'gridalicious_is_image_grid_content_active',
	        'label'		=> __( 'Featured Grid Content #', 'gridalicious-pro' ) . $i,
			'priority'	=> $priority . '.' . $i,
	        'section'  	=> 'gridalicious_featured_grid_content',
	        'settings'	=> 'gridalicious_theme_options[featured_grid_content_note_'. $i .']',
	        'type'     	=> 'description',
   		) ) );

		$wp_customize->add_setting( 'gridalicious_theme_options[featured_grid_content_image_'. $i .']', array(
			'capability'		=> 'edit_theme_options',
			'sanitize_callback'	=> 'gridalicious_sanitize_image',
		) );

		$wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, 'gridalicious_theme_options[featured_grid_content_image_'. $i .']' , array(
			'active_callback'	=> 'gridalicious_is_image_grid_content_active',
			'label'		=> __( 'Image', 'gridalicious-pro' ),
			'priority'	=> $priority . '.' . $i .$i,
			'section'   => 'gridalicious_featured_grid_content',
	        'settings'  => 'gridalicious_theme_options[featured_grid_content_image_'. $i .']',
		) ) );

		$wp_customize->add_setting( 'gridalicious_theme_options[featured_link_'. $i .']', array(
			'capability'		=> 'edit_theme_options',
			'sanitize_callback'	=> 'esc_url_raw',
		) );

		$wp_customize->add_control(  'gridalicious_theme_options[featured_link_'. $i .']', array(
			'active_callback'	=> 'gridalicious_is_image_grid_content_active',
			'label'		=> __( 'Link', 'gridalicious-pro' ),
	        'priority'	=> $priority . '.' .$i . $i  . $i,
			'section'   => 'gridalicious_featured_grid_content',
	        'settings'  => 'gridalicious_theme_options[featured_link_'. $i .']',
		) );

		$wp_customize->add_setting( 'gridalicious_theme_options[featured_target_'. $i .']', array(
	        'capability'		=> 'edit_theme_options',
			'sanitize_callback'	=> 'gridalicious_sanitize_checkbox',
		) );

		$wp_customize->add_control(  'gridalicious_theme_options[featured_target_'. $i .']', array(
			'active_callback'	=> 'gridalicious_is_image_grid_content_active',
			'label'		=> __( 'Check to Open Link in New Window/Tab', 'gridalicious-pro' ),
	        'priority'	=> $priority . '.' .$i  .$i  . $i . $i,
			'section'   => 'gridalicious_featured_grid_content',
	        'settings'  => 'gridalicious_theme_options[featured_target_'. $i .']',
			'type'		=> 'checkbox',
	    ) );

	    $wp_customize->add_setting( 'gridalicious_theme_options[featured_title_'. $i .']', array(
			'capability'		=> 'edit_theme_options',
			'sanitize_callback'	=> 'sanitize_text_field',
		) );

		$wp_customize->add_control(  'gridalicious_theme_options[featured_title_'. $i .']', array(
			'active_callback'	=> 'gridalicious_is_image_grid_content_active',
			'label'		=> __( 'Title', 'gridalicious-pro' ),
	        'priority'	=> $priority . '.' .$i .  $i.  $i .$i . $i,
			'section'   => 'gridalicious_featured_grid_content',
	        'settings'  => 'gridalicious_theme_options[featured_title_'. $i .']',
			'type'		=> 'text',
	    ) );
	}
// Featured Grid Content End
