<?php
/**
 * Footer Settings
 *
 * @package Chic Lifestyle
 */

add_action( 'customize_register', 'chic_lifestyle_customize_register_footer_section' );

function chic_lifestyle_customize_register_footer_section( $wp_customize ) {

    $wp_customize->add_section( 'chic_lifestyle_footer_section', array(
        'title'          => esc_html__( 'Footer Section', 'chic-lifestyle' ),
        'panel'          => 'chic_lifestyle_general_panel',
        'priority'       => 7,
    ) );

    $wp_customize->add_setting( 'chic_lifestyle_footer_layout', array(
      'capability'  => 'edit_theme_options',
      'default'     => '4',
      'sanitize_callback' => 'chic_lifestyle_sanitize_select',
      'transport' => 'postMessage',
    ) );
    
    $wp_customize->add_control( 'chic_lifestyle_footer_layout', array(
        'label'       =>  esc_html__( 'Number of footer widgets', 'chic-lifestyle' ),
        'section'     => 'chic_lifestyle_footer_section',
        'type'        => 'select',
        'default'     => '4',
        'choices'     =>  array(             
            '0' => 0,
            '1' => 1,
            '2' => 2,
            '3' => 3,
            '4' => 4,
        )
    ) );

    $wp_customize->selective_refresh->add_partial( 'chic_lifestyle_footer_layout', array(
        'selector' => '#footer-widgets',
        'settings' => array( 'chic_lifestyle_footer_layout' ),
        'render_callback' => 'chic_lifestyle_footer_widgets',
        'container_inclusive' => true,
    ) );

    $wp_customize->add_setting( 'copyright_text', array(
        'sanitize_callback'     =>  'wp_kses_post',
        'default'               =>  ''
    ) );

    $wp_customize->add_control( 'copyright_text', array(
        'label' => esc_html__( 'Copyright :', 'chic-lifestyle' ),
        'section' => 'chic_lifestyle_footer_section',
        'settings' => 'copyright_text',
        'type'=> 'textarea',
    ) );

    $wp_customize->selective_refresh->add_partial( 'copyright_text', array(
        'selector' => '.copyright',
    ) );

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

}