<?php
/**
 * Promotion Section options
 *
 * @package Theme Palace
 * @subpackage Power News
 * @since Power News 1.0.0
 */

// Add Promotion section
$wp_customize->add_section( 'power_news_promotion_section', array(
    'title'             => esc_html__( 'Promotion','power-news' ),
    'description'       => esc_html__( 'Promotion Section options.', 'power-news' ),
    'panel'             => 'power_news_front_page_panel',
    'active_callback'   => function( $control ) {
        return ( 
            power_news_is_second_layout( $control )
            ||
            power_news_is_third_layout( $control )
            ||
            power_news_is_fourth_layout( $control )
        );
    },
) );


// Promotion content enable control and setting
$wp_customize->add_setting( 'power_news_theme_options[promotion_section_enable]', array(
    'default'           =>  $options['promotion_section_enable'],
    'sanitize_callback' => 'power_news_sanitize_switch_control',
) );

$wp_customize->add_control( new Power_News_Switch_Control( $wp_customize, 'power_news_theme_options[promotion_section_enable]', array(
    'label'             => esc_html__( 'Promotion Section Enable', 'power-news' ),
    'section'           => 'power_news_promotion_section',
    'on_off_label'      => power_news_switch_options(),
) ) );

if ( isset( $wp_customize->selective_refresh ) ) {
    $wp_customize->selective_refresh->add_partial( 'power_news_theme_options[promotion_section_enable]', array(
        'selector'            => '.promotion-section .tooltiptext',
        'settings'            => 'power_news_theme_options[promotion_section_enable]',
    ) );
}


// Promotion content type control and setting
$wp_customize->add_setting( 'power_news_theme_options[promotion_content_type]', array(
    'default'           => $options['promotion_content_type'],
    'sanitize_callback' => 'power_news_sanitize_select',
) );

$wp_customize->add_control( 'power_news_theme_options[promotion_content_type]', array(
    'label'             => esc_html__( 'Content Type', 'power-news' ),
    'section'           => 'power_news_promotion_section',
    'type'              => 'select',
    'active_callback'   => 'power_news_is_promotion_section_enable',
    'choices'           => array( 
        'page'      => esc_html__( 'Page', 'power-news' ),
        'post'      => esc_html__( 'Post', 'power-news' ),
        'custom'    => esc_html__( 'Custom', 'power-news' ),
    ),
) );

// promotion pages drop down chooser control and setting
$wp_customize->add_setting( 'power_news_theme_options[promotion_content_page]', array(
    'sanitize_callback' => 'power_news_sanitize_page',
) );

$wp_customize->add_control( new Power_News_Dropdown_Chooser( $wp_customize, 'power_news_theme_options[promotion_content_page]', array(
    'label'             => esc_html__( 'Select Page', 'power-news' ),
    'section'           => 'power_news_promotion_section',
    'choices'           => power_news_page_choices(),
    'active_callback'   => 'power_news_is_promotion_section_content_page_enable',
) ) );

// promotion posts drop down chooser control and setting
$wp_customize->add_setting( 'power_news_theme_options[promotion_content_post]', array(
    'sanitize_callback' => 'power_news_sanitize_page',
) );

$wp_customize->add_control( new Power_News_Dropdown_Chooser( $wp_customize, 'power_news_theme_options[promotion_content_post]', array(
    'label'             => esc_html__( 'Select Post', 'power-news' ),
    'section'           => 'power_news_promotion_section',
    'choices'           => power_news_post_choices(),
    'active_callback'   => 'power_news_is_promotion_section_content_post_enable',
) ) );

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

$wp_customize->add_control( 'power_news_theme_options[promotion_title]', array(
    'label'             => esc_html__( 'Title', 'power-news' ),
    'section'           => 'power_news_promotion_section',
    'active_callback'   => 'power_news_is_promotion_section_content_custom_enable',
    'type'              => 'text',
) );


// promotion description setting and control
$wp_customize->add_setting( 'power_news_theme_options[promotion_description]', array(
    'sanitize_callback' => 'wp_kses_post',
    'default'           => $options['promotion_description'],
    'transport'         => 'postMessage',
) );

$wp_customize->add_control( 'power_news_theme_options[promotion_description]', array(
    'label'             => esc_html__( 'Description', 'power-news' ),
    'section'           => 'power_news_promotion_section',
    'active_callback'   => 'power_news_is_promotion_section_content_custom_enable',
    'type'              => 'textarea',
) );

// promotion image setting and control.
$wp_customize->add_setting( 'power_news_theme_options[promotion_image]', array(
    'sanitize_callback' => 'power_news_sanitize_image'
) );

$wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, 'power_news_theme_options[promotion_image]',
        array(
        'label'             => esc_html__( 'Image', 'power-news' ),
        'description'       => sprintf( esc_html__( 'Recommended size: %1$dpx x %2$dpx ', 'power-news' ), 512, 520 ),
        'section'           => 'power_news_promotion_section',
        'active_callback'   => 'power_news_is_promotion_section_content_custom_enable',
) ) );

// promotion btn title setting and control
$wp_customize->add_setting( 'power_news_theme_options[promotion_btn_title]', array(
    'sanitize_callback' => 'sanitize_text_field',
    'transport'         => 'postMessage',
) );

$wp_customize->add_control( 'power_news_theme_options[promotion_btn_title]', array(
    'label'             => esc_html__( 'Button Label', 'power-news' ),
    'section'           => 'power_news_promotion_section',
    'type'              => 'text',
    'active_callback'   =>  'power_news_is_promotion_section_enable',
) );

if ( isset( $wp_customize->selective_refresh ) ) {
    $wp_customize->selective_refresh->add_partial( 'power_news_theme_options[promotion_btn_title]', array(
        'selector'      => '#power_news_promotion_section .read-more .btn',
        'settings'      => 'power_news_theme_options[promotion_btn_title]',
        'container_inclusive' => false,
        'fallback_refresh'    => true,
        'render_callback'     => 'power_news_promotion_btn_title_partial',
    ) );
}

// promotion btn link setting and control
$wp_customize->add_setting( 'power_news_theme_options[promotion_btn_link]', array(
    'sanitize_callback' => 'esc_url_raw',
) );

$wp_customize->add_control( 'power_news_theme_options[promotion_btn_link]', array(
    'label'             => esc_html__( 'Button Url', 'power-news' ),
    'section'           => 'power_news_promotion_section',
    'type'              => 'url',
    'active_callback'   =>  'power_news_is_promotion_section_content_custom_enable',
) );