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

if ( ! function_exists( 'home_shifting_services_customizer_home_solution_register' ) ) :
function home_shifting_services_customizer_home_solution_register( $wp_customize ) {

    $wp_customize->add_section(
        'home_shifting_services_home_solution_settings',
        array (
            'priority'      => 25,
            'capability'    => 'edit_theme_options',
            'title'         => esc_html__( 'Solution Settings', 'home-shifting-services' )
        )
    );

    // Title label
    $wp_customize->add_setting( 
        'home_shifting_services_label_solution_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_solution_settings_title', 
        array(
            'label'       => esc_html__( 'Solution Settings', 'home-shifting-services' ),
            'section'     => 'home_shifting_services_home_solution_settings',
            'type'        => 'home-shifting-services-title',
            'settings'    => 'home_shifting_services_label_solution_settings_title',
        ) 
    ));

    $wp_customize->add_setting(
            'home_shifting_services_solution_section_bg_image',
            array(
                'default'           => '',
                'sanitize_callback' => 'home_shifting_services_sanitize_image',

            )
        );
        
        $wp_customize->add_control(
            new WP_Customize_Image_Control(
                $wp_customize, 'home_shifting_services_solution_section_bg_image', 
                array(
                    'label'           => sprintf( esc_html__( 'Background Image', 'home-shifting-services' ), ),
                    'settings'  => 'home_shifting_services_solution_section_bg_image',
                    'section'   => 'home_shifting_services_home_solution_settings'
                ) 
            )
        );

    $wp_customize->add_setting(
        'home_shifting_services_solution_main_heading',
        array(
            'default'           => '',
            'sanitize_callback' => 'sanitize_text_field',
        )
    );

    $wp_customize->add_control(
        'home_shifting_services_solution_main_heading',
        array(
            'label'           => sprintf( esc_html__( 'Main Heading', 'home-shifting-services' ), ),
            'section'         => 'home_shifting_services_home_solution_settings',
            'settings'        => 'home_shifting_services_solution_main_heading' ,
            'type'            => 'text',
        )
    );

    $wp_customize->add_setting(
        'home_shifting_services_solution_small_heading',
        array(
            'default'           => '',
            'sanitize_callback' => 'sanitize_text_field',
        )
    );

    $wp_customize->add_control(
        'home_shifting_services_solution_small_heading',
        array(
            'label'           => sprintf( esc_html__( 'Small Heading', 'home-shifting-services' ), ),
            'section'         => 'home_shifting_services_home_solution_settings',
            'settings'        => 'home_shifting_services_solution_small_heading' ,
            'type'            => 'text',
        )
    );

    $wp_customize->add_setting(
        'home_shifting_services_solution_text',
        array(
            'default'           => '',
            'sanitize_callback' => 'sanitize_text_field',
        )
    );

    $wp_customize->add_control(
        'home_shifting_services_solution_text',
        array(
            'label'           => sprintf( esc_html__( 'Text', 'home-shifting-services' ), ),
            'section'         => 'home_shifting_services_home_solution_settings',
            'settings'        => 'home_shifting_services_solution_text' ,
            'type'            => 'text',
        )
    );
    
    $wp_customize->add_setting( 'home_shifting_services_solution_increase', array(
        'default'           => '', 
        'sanitize_callback' => 'home_shifting_services_sanitize_number',
    ));

    // Add control for number of solution
    $wp_customize->add_control( 'home_shifting_services_solution_increase', array(
        'label'       => __( 'Number of Solution to Display', 'home-shifting-services' ),
        'section'     => 'home_shifting_services_home_solution_settings', 
        'type'        => 'number', 
        'input_attrs' => array(
            'min' => 1,
            'max' => 8,
        ),      
    ));

    $home_shifting_services_solution_count =  get_theme_mod('home_shifting_services_solution_increase');

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

    $wp_customize->add_setting(
            'home_shifting_services_solution_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_solution_image'.$i, 
                array(
                    'label'           => sprintf( esc_html__( 'Solution Image', 'home-shifting-services' ).$i, ),
                    'settings'  => 'home_shifting_services_solution_image'.$i,
                    'section'   => 'home_shifting_services_home_solution_settings'
                ) 
            )
        );

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

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

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

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

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

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

    }
}
endif;

add_action( 'customize_register', 'home_shifting_services_customizer_home_solution_register' );