<?php
/**
 * Footer Settings
 *
 * @package bootstrap_coach
 */

add_action( 'customize_register', 'bootstrap_coach_customize_register_footer_section' );

function bootstrap_coach_customize_register_footer_section( $wp_customize ) {

    $wp_customize->add_section( 'bootstrap_coach_footer_section', array(
        'title'          => esc_html__( 'Footer Section', 'bootstrap-coach' ),
        'panel'          => 'bootstrap_coach_general_panel',
        'priority'       => 5,
    ) );

    $wp_customize->add_setting( 'bootstrap_coach_footer_layout', array(
      'capability'  => 'edit_theme_options',
      'default'     => '4',
      'sanitize_callback' => 'bootstrap_coach_sanitize_select',
      'transport' => 'postMessage',
    ) );
    
    $wp_customize->add_control( 'bootstrap_coach_footer_layout', array(
        'label'       =>  esc_html__( 'Number of footer widgets', 'bootstrap-coach' ),
        'section'     => 'bootstrap_coach_footer_section',
        'type'        => 'select',
        'default'     => '4',
        'choices'     =>  array(             
            '0' => 0,
            '1' => 1,
            '2' => 2,
            '3' => 3,
            '4' => 4,
        )
    ) );

    $wp_customize->selective_refresh->add_partial( 'bootstrap_coach_footer_layout', array(
        'selector' => '#footer-widgets',
        'settings' => array( 'bootstrap_coach_footer_layout' ),
        'render_callback' => 'bootstrap_coach_footer_widgets',
        'container_inclusive' => true,
    ) );
        
    $wp_customize->add_setting( 'bs_copyright_text', array(
        'transport' => 'refresh',
        'sanitize_callback'     =>  'wp_kses_post',
        'default'               =>  ''
    ) );

    $wp_customize->add_control( 'bs_copyright_text', array(
        'label' => esc_html__( 'Copyright :', 'bootstrap-coach' ),
        'section' => 'bootstrap_coach_footer_section',
        'type'=> 'textarea',
    ) );

    $wp_customize->selective_refresh->add_partial( 'bs_copyright_text', array(
	    'selector' => '.footer .copyright span.editable',
        'render_callback' => 'bootstrap_coach_get_copyright'
	) );
    
    if ( fs_bootstrap_coach()->is_free_plan() ) {
        $wp_customize->add_setting( 'bootstrap_coach_footer_upgrade_to_pro', array(
            'sanitize_callback' => null,
        ) );
        $wp_customize->add_control( new Bootstrap_Coach_Control_Upgrade_To_Pro(
            $wp_customize, 'bootstrap_coach_footer_upgrade_to_pro', array(
                'section' => 'bootstrap_coach_footer_section',
                'settings'    => 'bootstrap_coach_footer_upgrade_to_pro',
                'title'   => __( 'Want the full control over your copyright?', 'bootstrap-coach' ),
                'items' => array(
                    'one'   => array(
                        'title' => __( 'Remove WordPress links from the copyright', 'bootstrap-coach' ),
                    ),
                ),
                'button_url'   => esc_url( 'https://thebootstrapthemes.com/coach/#free-vs-pro' ),
                'button_text'   => __( 'Upgrade Now', 'bootstrap-coach' ),
            )
        ) );
    }
}