<?php
/**
 * Theme Customizer Controls
 *
 * @package Legacy Wellness Coach
 */

if ( ! function_exists( 'legacy_wellness_coach_customizer_home_banner_register' ) ) :
function legacy_wellness_coach_customizer_home_banner_register( $wp_customize ) {
 	
 	$wp_customize->add_section(
        'legacy_wellness_coach_home_banner_settings',
        array (
            'priority'      => 25,
            'capability'    => 'edit_theme_options',
            'title'         => esc_html__( 'Banner Settings', 'legacy-wellness-coach' )
        )
    );

    // Title label
	$wp_customize->add_setting( 
		'legacy_wellness_coach_label_banner_settings_title', 
		array(
		    'sanitize_callback' => 'legacy_wellness_coach_sanitize_title',
		) 
	);

	$wp_customize->add_control( 
		new Legacy_Wellness_Coach_Title_Info_Control( $wp_customize, 'legacy_wellness_coach_label_banner_settings_title', 
		array(
		    'label'       => esc_html__( 'Banner Settings', 'legacy-wellness-coach' ),
		    'section'     => 'legacy_wellness_coach_home_banner_settings',
		    'type'        => 'legacy-wellness-coach-title',
		    'settings'    => 'legacy_wellness_coach_label_banner_settings_title',
		) 
	));

     $wp_customize->add_setting('legacy_wellness_coach_slide_number',array(
        'default' => '',
        'sanitize_callback' => 'legacy_wellness_coach_sanitize_number',
    ));
    $wp_customize->add_control('legacy_wellness_coach_slide_number',array(
        'label' => __('Number of slides to show','legacy-wellness-coach'),
        'section' => 'legacy_wellness_coach_home_banner_settings',
        'type'    => 'number',
        'input_attrs' => array(
            'min'  => 1,
            'max'  => 5,
        ),
    ));
      $legacy_wellness_coach_banner_count =  get_theme_mod('legacy_wellness_coach_slide_number');

        for($i=1; $i<=$legacy_wellness_coach_banner_count; $i++ ) {  

    // Button Image
    $wp_customize->add_setting(
        'legacy_wellness_coach_slide_image'.$i,
        array(
            'default'           => '',
            'sanitize_callback' => 'legacy_wellness_coach_sanitize_image',

        )
    );
    
    $wp_customize->add_control(
        new WP_Customize_Image_Control(
            $wp_customize, 'legacy_wellness_coach_slide_image'.$i, 
            array(
                'label'           => sprintf( esc_html__( 'Banner Image ', 'legacy-wellness-coach' ).$i, ),
                'settings'  => 'legacy_wellness_coach_slide_image'.$i,
                'section'   => 'legacy_wellness_coach_home_banner_settings'
            ) 
        )
    );

    // Banner Heading
    $wp_customize->add_setting(
        'legacy_wellness_coach_slide_sub_heading'.$i,
        array(
            'default'           => '',
            'sanitize_callback' => 'sanitize_text_field',
        )
    );

    $wp_customize->add_control(
        'legacy_wellness_coach_slide_sub_heading'.$i,
        array(
            'label'           => sprintf( esc_html__( 'Extra Banner Heading ', 'legacy-wellness-coach' ).$i, ),
            'section'         => 'legacy_wellness_coach_home_banner_settings',
            'settings'        => 'legacy_wellness_coach_slide_sub_heading'.$i ,
            'type'            => 'text',
        )
    );

    // Banner Heading
	$wp_customize->add_setting(
        'legacy_wellness_coach_slide_heading'.$i,
        array(
            'default'           => '',
            'sanitize_callback' => 'sanitize_text_field',
        )
    );

    $wp_customize->add_control(
        'legacy_wellness_coach_slide_heading'.$i,
        array(
            'label'           => sprintf( esc_html__( 'Banner Heading ( give maximum 6 words heading ) ', 'legacy-wellness-coach' ).$i, ),
            'section'         => 'legacy_wellness_coach_home_banner_settings',
            'settings'        => 'legacy_wellness_coach_slide_heading'.$i ,
            'type'            => 'text',
        )
    );

    // Banner Heading
    $wp_customize->add_setting(
        'legacy_wellness_coach_slide_text'.$i,
        array(
            'default'           => '',
            'sanitize_callback' => 'sanitize_text_field',
        )
    );

    $wp_customize->add_control(
        'legacy_wellness_coach_slide_text'.$i,
        array(
            'label'           => sprintf( esc_html__( 'Banner Text ', 'legacy-wellness-coach' ).$i, ),
            'section'         => 'legacy_wellness_coach_home_banner_settings',
            'settings'        => 'legacy_wellness_coach_slide_text'.$i ,
            'type'            => 'text',
        )
    );

    // banner Button
    $wp_customize->add_setting(
        'legacy_wellness_coach_slide_btntext'.$i,
        array(
            'default'           => '',
            'sanitize_callback' => 'sanitize_text_field',
        )
    );

    $wp_customize->add_control(
        'legacy_wellness_coach_slide_btntext'.$i,
        array(
            'label'           => sprintf( esc_html__( 'Banner Button Text ', 'legacy-wellness-coach' ).$i, ),
            'section'         => 'legacy_wellness_coach_home_banner_settings',
            'settings'        => 'legacy_wellness_coach_slide_btntext'.$i ,
            'type'            => 'text',
        )
    );

    // banner Button
    $wp_customize->add_setting(
        'legacy_wellness_coach_slide_btnurl'.$i,
        array(
            'default'           => '',
            'sanitize_callback' => 'esc_url_raw',
        )
    );

    $wp_customize->add_control(
        'legacy_wellness_coach_slide_btnurl'.$i,
        array(
            'label'           => sprintf( esc_html__( 'Banner Button Link ', 'legacy-wellness-coach' ).$i, ),
            'section'         => 'legacy_wellness_coach_home_banner_settings',
            'settings'        => 'legacy_wellness_coach_slide_btnurl'.$i ,
            'type'            => 'url',
        )
    );


    // banner Button
    $wp_customize->add_setting(
        'legacy_wellness_coach_slide_image_title'.$i,
        array(
            'default'           => '',
            'sanitize_callback' => 'sanitize_text_field',
        )
    );

    $wp_customize->add_control(
        'legacy_wellness_coach_slide_image_title'.$i,
        array(
            'label'           => sprintf( esc_html__( 'Image Title ', 'legacy-wellness-coach' ).$i, ),
            'section'         => 'legacy_wellness_coach_home_banner_settings',
            'settings'        => 'legacy_wellness_coach_slide_image_title'.$i ,
            'type'            => 'text',
        )
    );

    }
    // Slider Content Alignment Setting
    $wp_customize->add_setting(
        'legacy_wellness_coach_slider_content_alignment',
        array(
            'default'           => 'right',
            'sanitize_callback' => 'legacy_wellness_coach_sanitize_select',
        )
    );

    $wp_customize->add_control(
        'legacy_wellness_coach_slider_content_alignment',
        array(
            'label'    => esc_html__( 'Slider Content Alignment', 'legacy-wellness-coach' ),
            'section'  => 'legacy_wellness_coach_home_banner_settings',
            'settings' => 'legacy_wellness_coach_slider_content_alignment',
            'type'     => 'select',
            'choices'  => array(
                'left'   => esc_html__( 'Left', 'legacy-wellness-coach' ),
                'center' => esc_html__( 'Center', 'legacy-wellness-coach' ),
                'right'  => esc_html__( 'Right', 'legacy-wellness-coach' ),
            ),
        )
    );
}
endif;

add_action( 'customize_register', 'legacy_wellness_coach_customizer_home_banner_register' );