<?php
/**
 * Call To Action Section options
 *
 * @package Theme Palace
 * @subpackage enlightme Pro
 * @since enlightme Pro 1.0.0
 */

// Add Call To Action section
$wp_customize->add_section( 'enlightme_pro_cta_section', array(
    'title'             => esc_html__( 'Call To Action','enlightme-pro' ),
    'description'       => esc_html__( 'Call To Action Section options.', 'enlightme-pro' ),
    'panel'             => 'enlightme_pro_front_page_panel',
    'active_callback'   => function( $control ) {
        return (
            enlightme_pro_is_second_layout( $control )
        );
    },
) );

// Call To Action content enable control and setting
$wp_customize->add_setting( 'enlightme_pro_theme_options[cta_section_enable]', array(
    'default'           =>  $options['cta_section_enable'],
    'sanitize_callback' => 'enlightme_pro_sanitize_switch_control',
) );

$wp_customize->add_control( new Enlightme_Pro_Switch_Control( $wp_customize, 'enlightme_pro_theme_options[cta_section_enable]', array(
    'label'             => esc_html__( 'Call To Action Section Enable', 'enlightme-pro' ),
    'section'           => 'enlightme_pro_cta_section',
    'on_off_label'      => enlightme_pro_switch_options(),
) ) );

if ( isset( $wp_customize->selective_refresh ) ) {
    $wp_customize->selective_refresh->add_partial( 'enlightme_pro_theme_options[cta_section_enable]', array(
        'selector'            => '#business-cta-section .tooltiptext',
        'settings'            => 'enlightme_pro_theme_options[cta_section_enable]',
    ) );
}


// cta image setting and control.
$wp_customize->add_setting( 'enlightme_pro_theme_options[cta_image]', array(
    'sanitize_callback' => 'enlightme_pro_sanitize_image',
) );

$wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, 'enlightme_pro_theme_options[cta_image]',
    array(
    'label'             => esc_html__( 'Background Image ', 'enlightme-pro' ),
    'section'           => 'enlightme_pro_cta_section',
    'active_callback'   => 'enlightme_pro_is_cta_section_enable',
) ) );

// cta sub_title setting and control
$wp_customize->add_setting( 'enlightme_pro_theme_options[cta_sub_title]', array(
    'sanitize_callback' => 'sanitize_text_field',
    'default'           => $options['cta_sub_title'],
    'transport'         => 'postMessage',
) );

$wp_customize->add_control( 'enlightme_pro_theme_options[cta_sub_title]', array(
    'label'             => esc_html__( 'Sub Title', 'enlightme-pro' ),
    'section'           => 'enlightme_pro_cta_section',
    'active_callback'   => 'enlightme_pro_is_cta_section_enable',
    'type'              => 'text',
) );

// Abort if selective refresh is not available.
if ( isset( $wp_customize->selective_refresh ) ) {
    $wp_customize->selective_refresh->add_partial( 'enlightme_pro_theme_options[cta_sub_title]', array(
        'selector'            => '#business-cta-section div.section-header h3',
        'settings'            => 'enlightme_pro_theme_options[cta_sub_title]',
        'container_inclusive' => false,
        'fallback_refresh'    => true,
        'render_callback'     => 'enlightme_pro_cta_sub_title_partial',
    ) );
}

// Call To Action content type control and setting
$wp_customize->add_setting( 'enlightme_pro_theme_options[cta_content_type]', array(
    'default'           => $options['cta_content_type'],
    'sanitize_callback' => 'enlightme_pro_sanitize_select',
) );

$wp_customize->add_control( 'enlightme_pro_theme_options[cta_content_type]', array(
    'label'             => esc_html__( 'Content Type', 'enlightme-pro' ),
    'section'           => 'enlightme_pro_cta_section',
    'type'              => 'select',
    'active_callback'   => 'enlightme_pro_is_cta_section_enable',
    'choices'           => array( 
        'page'      => esc_html__( 'Page', 'enlightme-pro' ),
        'post'      => esc_html__( 'Post', 'enlightme-pro' ),
        'custom'    => esc_html__( 'Custom', 'enlightme-pro' ),
    ),
) );

// cta pages drop down chooser control and setting
$wp_customize->add_setting( 'enlightme_pro_theme_options[cta_content_page]', array(
    'sanitize_callback' => 'enlightme_pro_sanitize_page',
) );

$wp_customize->add_control( new Enlightme_Pro_Dropdown_Chooser( $wp_customize, 'enlightme_pro_theme_options[cta_content_page]', array(
    'label'             => esc_html__( 'Select Page', 'enlightme-pro' ),
    'section'           => 'enlightme_pro_cta_section',
    'choices'           => enlightme_pro_page_choices(),
    'active_callback'   => 'enlightme_pro_is_cta_section_content_page_enable',
) ) );

// cta posts drop down chooser control and setting
$wp_customize->add_setting( 'enlightme_pro_theme_options[cta_content_post]', array(
    'sanitize_callback' => 'enlightme_pro_sanitize_page',
) );

$wp_customize->add_control( new Enlightme_Pro_Dropdown_Chooser( $wp_customize, 'enlightme_pro_theme_options[cta_content_post]', array(
    'label'             => esc_html__( 'Select Post', 'enlightme-pro' ),
    'section'           => 'enlightme_pro_cta_section',
    'choices'           => enlightme_pro_post_choices(),
    'active_callback'   => 'enlightme_pro_is_cta_section_content_post_enable',
) ) );

// cta title setting and control
$wp_customize->add_setting( 'enlightme_pro_theme_options[cta_title]', array(
    'sanitize_callback' => 'sanitize_text_field',
    'default'           => $options['cta_title'],
) );

$wp_customize->add_control( 'enlightme_pro_theme_options[cta_title]', array(
    'label'             => esc_html__( 'Title', 'enlightme-pro' ),
    'section'           => 'enlightme_pro_cta_section',
    'active_callback'   => 'enlightme_pro_is_cta_section_content_custom_enable',
    'type'              => 'text',
) );

// enlightme btn title setting and control
$wp_customize->add_setting( 'enlightme_pro_theme_options[cta_btn_title]', array(
    'sanitize_callback' => 'sanitize_text_field',
    'default'           => $options['cta_btn_title'],
    'transport'         => 'postMessage',
) );

$wp_customize->add_control( 'enlightme_pro_theme_options[cta_btn_title]', array(
    'label'             => esc_html__( 'Button Label', 'enlightme-pro' ),
    'section'           => 'enlightme_pro_cta_section',
    'active_callback'   => 'enlightme_pro_is_cta_section_enable',
    'type'              => 'text',
) );

// Abort if selective refresh is not available.
if ( isset( $wp_customize->selective_refresh ) ) {
    $wp_customize->selective_refresh->add_partial( 'enlightme_pro_theme_options[cta_btn_title]', array(
        'selector'            => '#business-cta-section div.read-more a',
        'settings'            => 'enlightme_pro_theme_options[cta_btn_title]',
        'container_inclusive' => false,
        'fallback_refresh'    => true,
        'render_callback'     => 'enlightme_pro_cta_btn_title_partial',
    ) );
}

// enlightme btn link setting and control
$wp_customize->add_setting( 'enlightme_pro_theme_options[cta_btn_link]', array(
    'sanitize_callback' => 'esc_url_raw',
) );

$wp_customize->add_control( 'enlightme_pro_theme_options[cta_btn_link]', array(
    'label'             => esc_html__( 'Button Link', 'enlightme-pro' ),
    'section'           => 'enlightme_pro_cta_section',
    'active_callback'   => 'enlightme_pro_is_cta_section_content_custom_enable',
    'type'              => 'url',
) );