<?php
/**
 * Latest Post Section options
 *
 * @package Theme Palace
 * @subpackage Rise Magazine
 * @since Rise Magazine 1.0.0
 */

// Add Latest Post section
$wp_customize->add_section( 'rise_magazine_latest_posts_section',
    array(
        'title'             => esc_html__( 'Latest Post','rise-magazine' ),
        'description'       => esc_html__( 'Latest Post Section options.', 'rise-magazine' ),
        'panel'             => 'rise_magazine_front_page_panel',
    )
);

// Latest Post content enable control and setting
$wp_customize->add_setting( 'rise_magazine_theme_options[latest_posts_section_enable]',
    array(
        'default'           =>  $options['latest_posts_section_enable'],
        'sanitize_callback' => 'rise_magazine_sanitize_switch_control',
    )
);

$wp_customize->add_control( new Rise_Magazine_Switch_Control( $wp_customize,
    'rise_magazine_theme_options[latest_posts_section_enable]',
        array(
            'label'             => esc_html__( 'Latest Post Section Enable', 'rise-magazine' ),
            'section'           => 'rise_magazine_latest_posts_section',
            'on_off_label'      => rise_magazine_switch_options(),
        ) 
    )
);

// latest_post title setting and control
$wp_customize->add_setting( 'rise_magazine_theme_options[latest_posts_title]',
    array(
        'sanitize_callback' => 'sanitize_text_field',
        'default'           => $options['latest_posts_title'],
        'transport'         => 'postMessage',
    )
);

$wp_customize->add_control( 'rise_magazine_theme_options[latest_posts_title]',
    array(
        'label'             => esc_html__( 'Section Title', 'rise-magazine' ),
        'section'           => 'rise_magazine_latest_posts_section',
        'active_callback'   => 'rise_magazine_is_latest_posts_section_enable',
        'type'              => 'text',
    )
);

// Abort if selective refresh is not available.
if ( isset( $wp_customize->selective_refresh ) ) {
    $wp_customize->selective_refresh->add_partial( 'rise_magazine_theme_options[latest_posts_title]',
        array(
            'selector'            => '#rise_magazine_latest_posts_section .section-header h2',
            'settings'            => 'rise_magazine_theme_options[latest_posts_title]',
            'container_inclusive' => false,
            'fallback_refresh'    => true,
            'render_callback'     => 'rise_magazine_latest_posts_title_partial',
        )
    );
}

// Latest Posts Excerpt length setting and control.
$wp_customize->add_setting( 'rise_magazine_theme_options[latest_posts_excerpt_length]',
	array(
		'sanitize_callback' => 'rise_magazine_sanitize_number_range',
		'default'			=> $options['latest_posts_excerpt_length'],
	)
);

$wp_customize->add_control( 'rise_magazine_theme_options[latest_posts_excerpt_length]',
	array(
		'label'       		=> esc_html__( 'Excerpt Length', 'rise-magazine' ),
		'description' 		=> esc_html__( 'Total words to be displayed in Latest posts section', 'rise-magazine' ),
		'section'     		=> 'rise_magazine_latest_posts_section',
		'type'        		=> 'number',
		'active_callback' 	=> 'rise_magazine_is_latest_posts_section_enable',
	)
);


// Add dropdown category setting and control.
$wp_customize->add_setting(  'rise_magazine_theme_options[latest_posts_content_category]',
    array(
        'sanitize_callback' => 'rise_magazine_sanitize_single_category',
    )
);

$wp_customize->add_control( new Rise_Magazine_Dropdown_Taxonomies_Control( $wp_customize,
    'rise_magazine_theme_options[latest_posts_content_category]',
        array(
            'label'             => esc_html__( 'Select Category', 'rise-magazine' ),
            'description'       => esc_html__( 'Note: Latest selected no of posts will be shown from selected category', 'rise-magazine' ),
            'section'           => 'rise_magazine_latest_posts_section',
            'type'              => 'dropdown-taxonomies',
            'active_callback'   => 'rise_magazine_is_latest_posts_section_enable'
        )
    )
);
