<?php
/**
 * Theme Customizer Controls
 *
 * @package somalite
 */


if ( ! function_exists( 'somalite_customizer_preloader_register' ) ) :
function somalite_customizer_preloader_register( $wp_customize ) {
     
    // Preloader Settings
    $wp_customize->add_section(
        'soma_preloader_settings',
        array (
            'priority'      => 25,
            'capability'    => 'edit_theme_options',
            'theme_supports'=> '',
            'title'         => esc_html__( 'Preloader Settings', 'somalite' )
        )
    );

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

    $wp_customize->add_control( 
        new Somalite_Title_Info_Control( $wp_customize, 'somalite_label_preloader_settings', 
        array(
            'label'       => esc_html__( 'Preloader Settings', 'somalite' ),
            'section'     => 'soma_preloader_settings',
            'type'        => 'somalite-title',
            'settings'    => 'somalite_label_preloader_settings',
        ) 
    ));

    // Preloader Enable radio button 
    $wp_customize->add_setting(
        'sm_preloader_display',
        array(
            'type' => 'theme_mod',
            'default'           => true,
            'sanitize_callback' => 'somalite_sanitize_checkbox'
        )
    );

    $wp_customize->add_control( 
        new Somalite_Toggle_Control( $wp_customize, 'sm_preloader_display', 
        array(
            'section'     => 'soma_preloader_settings',
            'type'        => 'somalite-toggle',
            'settings'    => 'sm_preloader_display',
            'label'         => esc_html__( 'Enable Preloader for site:', 'somalite' ),
            'description'   => esc_html__( 'Choose whether to show a preloader before a site opens', 'somalite' ),
        ) 
    ));

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

    $wp_customize->add_control( 
        new Somalite_Title_Info_Control( $wp_customize, 'somalite_label_preloader_image_settings', 
        array(
            'label'       => esc_html__( 'Preloader Image', 'somalite' ),
            'section'     => 'soma_preloader_settings',
            'type'        => 'somalite-title',
            'settings'    => 'somalite_label_preloader_image_settings',
            'active_callback' => 'somalite_site_preloader_enable',
        ) 
    ));

    // Image for preloader 
    $wp_customize->add_setting(
        'sm_preloader_image',
        array(
            'type' => 'theme_mod',
            'sanitize_callback' => 'somalite_sanitize_image'
        )
    );

    $wp_customize->add_control(
      new WP_Customize_Image_Control(
          $wp_customize,
          'sm_preloader_image',
          array(
              'settings'      => 'sm_preloader_image',
              'section'       => 'soma_preloader_settings',
              'label'         => esc_html__( 'Preloader Image', 'somalite' ),
              'description'   => esc_html__( 'Upload image for preloader', 'somalite' ),
              'active_callback' => 'somalite_site_preloader_enable',
          )
      )
    );

}
endif;

add_action( 'customize_register', 'somalite_customizer_preloader_register' );