<?php
/**
 * Theme Customizer Controls
 *
 * @package Home Shifting Services
 */

if ( ! function_exists( 'home_shifting_services_customizer_home_banner_register' ) ) :
function home_shifting_services_customizer_home_banner_register( $wp_customize ) {
 	
 	$wp_customize->add_section(
        'home_shifting_services_home_banner_settings',
        array (
            'priority'      => 25,
            'capability'    => 'edit_theme_options',
            'title'         => esc_html__( 'Banner Settings', 'home-shifting-services' )
        )
    );

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

	$wp_customize->add_control( 
		new Home_Shifting_Services_Title_Info_Control( $wp_customize, 'home_shifting_services_label_banner_settings_title', 
		array(
		    'label'       => esc_html__( 'Banner Settings', 'home-shifting-services' ),
		    'section'     => 'home_shifting_services_home_banner_settings',
		    'type'        => 'home-shifting-services-title',
		    'settings'    => 'home_shifting_services_label_banner_settings_title',
		) 
	));

    $wp_customize->add_setting('home_shifting_services_slider_increase',array(
        'default' => '',
        'sanitize_callback' => 'home_shifting_services_sanitize_number',
    ));
    $wp_customize->add_control('home_shifting_services_slider_increase',array(
        'label' => __('Number of slides to show','home-shifting-services'),
        'section' => 'home_shifting_services_home_banner_settings',
        'type'    => 'number'
    ));
      $home_shifting_services_banner_count =  get_theme_mod('home_shifting_services_slider_increase');

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

    $wp_customize->add_setting(
        'home_shifting_services_banner_image'.$i,
        array(
            'default'           => '',
            'sanitize_callback' => 'home_shifting_services_sanitize_image',

        )
    );
    
    $wp_customize->add_control(
        new WP_Customize_Image_Control(
            $wp_customize, 'home_shifting_services_banner_image'.$i, 
            array(
                'label'           => sprintf( esc_html__( 'Banner Image', 'home-shifting-services' ).$i, ),
                'settings'  => 'home_shifting_services_banner_image'.$i,
                'section'   => 'home_shifting_services_home_banner_settings'
            ) 
        )
    );

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

    $wp_customize->add_control(
        'home_shifting_services_banner_heading'.$i,
        array(
            'label'           => sprintf( esc_html__( 'Banner Heading', 'home-shifting-services' ).$i, ),
            'section'         => 'home_shifting_services_home_banner_settings',
            'settings'        => 'home_shifting_services_banner_heading'.$i ,
            'type'            => 'text',
        )
    );

    $wp_customize->add_setting(
        'home_shifting_services_banner_text'.$i,
        array(
            'default'           => '',
            'sanitize_callback' => 'sanitize_text_field',
        )
    );

    $wp_customize->add_control(
        'home_shifting_services_banner_text'.$i,
        array(
            'label'           => sprintf( esc_html__( 'Banner Text', 'home-shifting-services' ).$i, ),
            'section'         => 'home_shifting_services_home_banner_settings',
            'settings'        => 'home_shifting_services_banner_text'.$i ,
            'type'            => 'text',
        )
    );

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

    $wp_customize->add_control(
        'home_shifting_services_banner_button_link'.$i,
        array(
            'label'           => sprintf( esc_html__( 'Banner Button Link', 'home-shifting-services' ).$i, ),
            'section'         => 'home_shifting_services_home_banner_settings',
            'settings'        => 'home_shifting_services_banner_button_link'.$i ,
            'type'            => 'url',
        )
    );

    $wp_customize->add_setting(
        'home_shifting_services_banner_button_link2'.$i,
        array(
            'default'           => '',
            'sanitize_callback' => 'esc_url_raw',
        )
    );

    $wp_customize->add_control(
        'home_shifting_services_banner_button_link2'.$i,
        array(
            'label'           => sprintf( esc_html__( 'Banner Button2 Link', 'home-shifting-services' ).$i, ),
            'section'         => 'home_shifting_services_home_banner_settings',
            'settings'        => 'home_shifting_services_banner_button_link2'.$i ,
            'type'            => 'url',
        )
    );

    } 

    // Slider Content Alignment Setting
    $wp_customize->add_setting(
        'home_shifting_services_slider_content_alignment',
        array(
            'default'           => 'center',
            'sanitize_callback' => 'home_shifting_services_sanitize_select',
        )
    );

    $wp_customize->add_control(
        'home_shifting_services_slider_content_alignment',
        array(
            'label'    => esc_html__( 'Slider Content Alignment', 'home-shifting-services' ),
            'section'  => 'home_shifting_services_home_banner_settings',
            'settings' => 'home_shifting_services_slider_content_alignment',
            'type'     => 'select',
            'choices'  => array(
                'left'   => esc_html__( 'Left', 'home-shifting-services' ),
                'center' => esc_html__( 'Center', 'home-shifting-services' ),
                'right'  => esc_html__( 'Right', 'home-shifting-services' ),
            ),
        )
    );    
}
endif;

add_action( 'customize_register', 'home_shifting_services_customizer_home_banner_register' );