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


if ( ! function_exists( 'mestore_customizer_preloader_register' ) ) :
function mestore_customizer_preloader_register( $wp_customize ) {
 
 	$wp_customize->add_section(
        'mestore_preloader_settings',
        array (
            'priority'      => 25,
            'capability'    => 'edit_theme_options',
            'title'         => esc_html__( 'Preloader Settings', 'mestore' )
        )
    );

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

	$wp_customize->add_control( 
		new MeStore_Title_Info_Control( $wp_customize, 'mestore_label_preloader_settings_title', 
		array(
		    'label'       => esc_html__( 'Preloader Settings', 'mestore' ),
		    'section'     => 'mestore_preloader_settings',
		    'type'        => 'mestore-title',
		    'settings'    => 'mestore_label_preloader_settings_title',
		) 
	));

	// Add an option to enable the preloader
	$wp_customize->add_setting( 
		'mestore_enable_preloader', 
		array(
		    'default'           => true,
		    'type'              => 'theme_mod',
		    'sanitize_callback' => 'mestore_sanitize_checkbox',
		) 
	);

	$wp_customize->add_control( 
		new MeStore_Toggle_Control( $wp_customize, 'mestore_enable_preloader', 
		array(
		    'label'       => esc_html__( 'Show Preloader', 'mestore' ),
		    'section'     => 'mestore_preloader_settings',
		    'type'        => 'mestore-toggle',
		    'settings'    => 'mestore_enable_preloader',
		) 
	));

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

	$wp_customize->add_control( 
		new MeStore_Title_Info_Control( $wp_customize, 'mestore_label_preloader_text_title', 
		array(
		    'label'       => esc_html__( 'Preloader Text', 'mestore' ),
		    'section'     => 'mestore_preloader_settings',
		    'type'        => 'mestore-title',
		    'settings'    => 'mestore_label_preloader_text_title',
		    'active_callback' => 'mestore_preloader_settings_enable',
		) 
	));


	// Add an option to enable the preloader text
	$wp_customize->add_setting( 
		'mestore_enable_preloader_text', 
		array(
		    'default'           => false,
		    'type'              => 'theme_mod',
		    'sanitize_callback' => 'mestore_sanitize_checkbox',
		) 
	);

	$wp_customize->add_control( 
		new MeStore_Toggle_Control( $wp_customize, 'mestore_enable_preloader_text', 
		array(
		    'label'       => esc_html__( 'Enable Preloader Text', 'mestore' ),
		    'section'     => 'mestore_preloader_settings',
		    'type'        => 'mestore-toggle',
		    'settings'    => 'mestore_enable_preloader_text',
		    'active_callback' => 'mestore_preloader_settings_enable',
		) 
	));


	// Add text
    $wp_customize->add_setting(
        'mestore_preloader_text',
        array(
            'type' => 'theme_mod',
            'default'           => esc_html__( 'loading', 'mestore' ),
            'sanitize_callback' => 'mestore_sanitize_text_field',
        )
    );

    $wp_customize->add_control(
        'mestore_preloader_text',
        array(
            'settings'      => 'mestore_preloader_text',
            'section'       => 'mestore_preloader_settings',
            'type'          => 'textbox',
            'label'         => esc_html__( 'Preloader Text', 'mestore' ),
            'active_callback' => 'mestore_preloader_text_settings_enable',
        )
    );

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

	$wp_customize->add_control( 
		new MeStore_Title_Info_Control( $wp_customize, 'mestore_label_preloader_image_title', 
		array(
		    'label'       => esc_html__( 'Preloader Image', 'mestore' ),
		    'section'     => 'mestore_preloader_settings',
		    'type'        => 'mestore-title',
		    'settings'    => 'mestore_label_preloader_image_title',
		    'active_callback' => 'mestore_preloader_settings_enable',
		) 
	));

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

    $wp_customize->add_control(
      	new WP_Customize_Image_Control(
      	$wp_customize,
          'mestore_preloader_image',
          array(
              'settings'      => 'mestore_preloader_image',
              'section'       => 'mestore_preloader_settings',
              'label'         => esc_html__( 'Preloader Image', 'mestore' ),
              'description'   => esc_html__( 'Upload image for preloader', 'mestore' ),
              'active_callback' => 'mestore_preloader_settings_enable',
      	))
    ); 

}
endif;

add_action( 'customize_register', 'mestore_customizer_preloader_register' );