<?php
/**
 * CTA Section Settings
 *
 * @package Feminine_Lifestyle_Blog
 */
if ( ! function_exists( 'feminine_lifestyle_blog_cta_settings' ) ) :

function feminine_lifestyle_blog_cta_settings( $wp_customize ) {
    
    /** CTA Section Settings */
    $wp_customize->add_section(
        'cta_section',
        array(
            'title'    => __( 'CTA Section', 'feminine-lifestyle-blog' ),
            'priority' => 75,
            'panel'    => 'homepage_settings',
        )
    );

    /** Enable CTA Section */
    $wp_customize->add_setting( 
        'ed_cta_section', 
        array(
            'default'           => false,
            'sanitize_callback' => 'feminine_lifestyle_blog_sanitize_checkbox'
        ) 
    );
    
    $wp_customize->add_control(
        new Feminine_Lifestyle_Blog_Toggle_Control( 
            $wp_customize,
            'ed_cta_section',
            array(
                'section'     => 'cta_section',
                'label'       => __( 'Enable CTA Section', 'feminine-lifestyle-blog' ),
            )
        )
    );

    /** Title Text */
    $wp_customize->add_setting( 
        'cta_title', 
        array(
            'default'           => esc_html__( 'Ready to explore exciting adventures?', 'feminine-lifestyle-blog' ), 
            'sanitize_callback' => 'sanitize_text_field',
            'transport'         => 'postMessage'
        ) 
    );
    
    $wp_customize->add_control(
        'cta_title',
        array(
            'section'         => 'cta_section',
            'label'           => __( 'Section Title', 'feminine-lifestyle-blog' ),
            'type'            => 'text',
        )   
    );

    $wp_customize->selective_refresh->add_partial( 'cta_title', array(
        'selector'          => '.cta-section .cta-section-wrapper .content-box h2.cta-section-title',
        'render_callback'   => 'feminine_lifestyle_blog_get_cta_title',
    ) );

    /** Content Text */
    $wp_customize->add_setting( 
        'cta_content', 
        array(
            'default'           => '', 
            'sanitize_callback' => 'wp_kses_post',
            'transport'         => 'postMessage'
        ) 
    );
    
    $wp_customize->add_control(
        'cta_content',
        array(
            'section'         => 'cta_section',
            'label'           => __( 'Section Content', 'feminine-lifestyle-blog' ),
            'type'            => 'textarea',
        )   
    );

    $wp_customize->selective_refresh->add_partial( 'cta_content', array(
        'selector'          => '.cta-section .cta-section-wrapper .content-box .cta_content',
        'render_callback'   => 'feminine_lifestyle_blog_get_cta_content',
    ) );

    $wp_customize->add_setting(
        'cta_btn_label',
        array(
            'default'           => '',
            'sanitize_callback' => 'sanitize_text_field',
            'transport'         => 'postMessage'
        )
    );
    
    $wp_customize->add_control(
        'cta_btn_label',
        array(
            'type'            => 'text',
            'section'         => 'cta_section',
            'label'           => __( 'Button Label', 'feminine-lifestyle-blog' ),

        )
    );

    $wp_customize->selective_refresh->add_partial( 'cta_btn_label', array(
        'selector'          => '.cta-section .cta-section-wrapper .content-box .primary-btn',
        'render_callback'   => 'feminine_lifestyle_blog_get_cta_btn_label',
    ) );

    /** Notification Button Link */
    $wp_customize->add_setting(
        'cta_btn_url',
        array(
            'default'           => '',
            'sanitize_callback' => 'esc_url_raw' 
        )
    );
    
    $wp_customize->add_control(
        'cta_btn_url',
        array(
            'type'            => 'text',
            'section'         => 'cta_section',
            'label'           => __( 'Button Link', 'feminine-lifestyle-blog' ),

        )
    );

    $wp_customize->add_setting(
        'cta_image',
        array(
            'default'           => '',
            'sanitize_callback' => 'feminine_lifestyle_blog_sanitize_number_absint',
        )
    );
    
    $wp_customize->add_control(
        new WP_Customize_Cropped_Image_Control(
            $wp_customize,
            'cta_image',
            array(
                'label'           => __( 'Upload CTA Image', 'feminine-lifestyle-blog' ),
                'description'      => __( 'The recommended image size for this section: 1920px by 450px.', 'feminine-lifestyle-blog'),
                'section'         => 'cta_section',
                'height'          => 450,  // Cropped Height
                'width'           => 1920,   // Cropper Width
                'flex_width'      => true,  //Flexible Width
                'flex_height'     => true,  // Flexible Heiht
            )
        )
    );

}
endif;
add_action( 'customize_register', 'feminine_lifestyle_blog_cta_settings' );