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

add_action( 'customize_register', 'relax_spa_customize_register_footer_section' );

function relax_spa_customize_register_footer_section( $wp_customize ) {

    $wp_customize->add_section( 'relax_spa_footer_section', array(
        'title'          => esc_html__( 'Footer Section', 'relax-spa' ),
        'panel'          => 'relax_spa_general_panel',
        'priority'       => 5,
    ) );

    $wp_customize->add_setting( 'relax_spa_footer_layout', array(
      'capability'  => 'edit_theme_options',
      'default'     => '4',
      'sanitize_callback' => 'relax_spa_sanitize_select',
      'transport' => 'postMessage',
    ) );
    
    $wp_customize->add_control( 'relax_spa_footer_layout', array(
        'label'       =>  esc_html__( 'Number of footer widgets', 'relax-spa' ),
        'section'     => 'relax_spa_footer_section',
        'type'        => 'select',
        'default'     => '4',
        'choices'     =>  array(
            '0' => 0,
            '1' => 1,
            '2' => 2,
            '3' => 3,
            '4' => 4,
        )
    ) );

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

    $wp_customize->add_control( 'bs_copyright_text', array(
        'label' => esc_html__( 'Copyright :', 'relax-spa' ),
        'section' => 'relax_spa_footer_section',
        'type'=> 'textarea',
    ) );

    $wp_customize->selective_refresh->add_partial( 'bs_copyright_text', array(
	    'selector' => '.footer .copyright span.editable',
        'render_callback' => 'relax_spa_get_copyright'
	) );

    if ( fs_relax_spa()->is_free_plan() ) {
        $wp_customize->add_setting( 'relax_spa_footer_upgrade_to_pro', array(
            'sanitize_callback' => null,
        ) );
        $wp_customize->add_control( new Relax_Spa_Control_Upgrade_To_Pro(
            $wp_customize, 'relax_spa_footer_upgrade_to_pro', array(
                'section' => 'relax_spa_footer_section',
                'settings'    => 'relax_spa_footer_upgrade_to_pro',
                'title'   => __( 'Want the full control over your copyright?', 'relax-spa' ),
                'items' => array(
                    'one'   => array(
                        'title' => __( 'Remove WordPress links from the copyright', 'relax-spa' ),
                    ),
                ),
                'button_url'   => esc_url( 'https://thebootstrapthemes.com/relax-spa/#free-vs-pro' ),
                'button_text'   => __( 'Upgrade Now', 'relax-spa' ),
            )
        ) );
    }
}