<?php
/**
 * Theme Customizer Controls
 *
 * @package Kindergarten Art School
 */

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

    $wp_customize->add_section(
        'kindergarten_art_school_home_services_settings',
        array (
            'priority'      => 25,
            'capability'    => 'edit_theme_options',
            'title'         => esc_html__( 'Services Settings', 'kindergarten-art-school' )
        )
    );

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

    $wp_customize->add_control( 
        new Kindergarten_Art_School_Title_Info_Control( $wp_customize, 'kindergarten_art_school_label_product_settings_title', 
        array(
            'label'       => esc_html__( 'Services Settings', 'kindergarten-art-school' ),
            'section'     => 'kindergarten_art_school_home_services_settings',
            'type'        => 'kindergarten-art-school-title',
            'settings'    => 'kindergarten_art_school_label_product_settings_title',
        ) 
    ));

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

    $wp_customize->add_control(
        'kindergarten_art_school_services_main_heading',
        array(
            'label'           => sprintf( esc_html__( 'Main Heading', 'kindergarten-art-school' ), ),
            'section'         => 'kindergarten_art_school_home_services_settings',
            'settings'        => 'kindergarten_art_school_services_main_heading' ,
            'type'            => 'text',
        )
    );

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

    $wp_customize->add_control(
        'kindergarten_art_school_services_text',
        array(
            'label'           => sprintf( esc_html__( 'Text', 'kindergarten-art-school' ), ),
            'section'         => 'kindergarten_art_school_home_services_settings',
            'settings'        => 'kindergarten_art_school_services_text' ,
            'type'            => 'text',
        )
    );

   $wp_customize->add_setting( 'kindergarten_art_school_services_increase', array(
        'default'           => '', 
        'sanitize_callback' => 'kindergarten_art_school_sanitize_number',
    ));

    // Add control for number of products
    $wp_customize->add_control( 'kindergarten_art_school_services_increase', array(
        'label'       => __( 'Number of Services to Display', 'kindergarten-art-school' ),
        'section'     => 'kindergarten_art_school_home_services_settings', 
        'type'        => 'number', 
        'input_attrs' => array(
            'min' => 1,
            'max' => 8,
        ),      
    ));

    $kindergarten_art_school_services_count =  get_theme_mod('kindergarten_art_school_services_increase');

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

    $wp_customize->add_setting(
            'kindergarten_art_school_services_image'.$i,
            array(
                'default'           => '',
                'sanitize_callback' => 'kindergarten_art_school_sanitize_image',

            )
        );
        
        $wp_customize->add_control(
            new WP_Customize_Image_Control(
                $wp_customize, 'kindergarten_art_school_services_image'.$i, 
                array(
                    'label'           => sprintf( esc_html__( 'Services Image', 'kindergarten-art-school' ).$i, ),
                    'settings'  => 'kindergarten_art_school_services_image'.$i,
                    'section'   => 'kindergarten_art_school_home_services_settings'
                ) 
            )
        );

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

    $wp_customize->add_control(
        'kindergarten_art_school_services_inner_heading'.$i,
        array(
            'label'           => sprintf( esc_html__( 'Inner Heading', 'kindergarten-art-school' ).$i, ),
            'section'         => 'kindergarten_art_school_home_services_settings',
            'settings'        => 'kindergarten_art_school_services_inner_heading'.$i ,
            'type'            => 'text',
        )
    );
    }
}
endif;

add_action( 'customize_register', 'kindergarten_art_school_customizer_home_services_register' );