<?php
/**
 * anirohotellight Theme Customizer
 *
 * @package anirohotellight
 */

/**
 * Add postMessage support for site title and description for the Theme Customizer.
 *
 * @param WP_Customize_Manager $wp_customize Theme Customizer object.
 */
function anirohotellight_customize_register( $wp_customize ) {
	$wp_customize->get_setting( 'blogname' )->transport         = 'postMessage';
	$wp_customize->get_setting( 'blogdescription' )->transport  = 'postMessage';
   
//******************************************************************************
// Add site logo to the standard section "title_tagline"
//******************************************************************************
    
	$wp_customize->add_setting( 'anirohotellight_logo', array(
                'default' => '',
		'sanitize_callback' => 'esc_url_raw',
	));
        
	$wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, 'anirohotellight_logo', array( 
		'label'    => esc_html__( 'Logo', 'aniro-hotel-light' ),
		'type'           => 'image',
		'section'  => 'title_tagline', 
		'settings' => 'anirohotellight_logo',
		'priority' => 90,
	))); 
	
	// Logo Width
	$wp_customize->add_setting( 'anirohotellight_logo_size', array(
	    'sanitize_callback' => 'absint',
            'default'	        => 50,
	));

	$wp_customize->add_control ( 'anirohotellight_logo_size', array( 
		'type'        => 'number',
                'label'    => esc_html__( 'Change the width of the Logo.', 'aniro-hotel-light' ),
		'description'    => esc_html__( 'Max value 400px, min value 20px', 'aniro-hotel-light' ),
		'section'  => 'title_tagline', 
		'settings' => 'anirohotellight_logo_size',  
		'priority'   => 91,
                'input_attrs' => array(
                    'min'   => 20,
                    'max'   => 245,
                    'step'  => 5,
                    'style' => 'margin-bottom: 15px; padding: 15px;',
        ),
	));     

        //Add hotel data
        //Add address
	$wp_customize->add_setting('anirohotellight_address', array(
			'default'            => '221b, Baker street, London, 10000',
			'sanitize_callback'  => 'wp_filter_nohtml_kses'
		)
	);
	$wp_customize->add_control('anirohotellight_address', array(
			'section'  => 'title_tagline',
                        'priority'   => 95,
			'label'    => esc_html__( 'Hotel address:', 'aniro-hotel-light' ),
			'type'     => 'text'
		)
	);        
        //Add e-mail
	$wp_customize->add_setting('anirohotellight_email', array(
			'default'            => 'aniro@gmail.com',
			'sanitize_callback'  => 'sanitize_email'
		)
	);
	$wp_customize->add_control('anirohotellight_email', array(
			'section'  => 'title_tagline',
                        'priority'   => 100,
			'label'    => esc_html__( 'Hotel e-mail address:', 'aniro-hotel-light' ),
			'type'     => 'text'
		)
	);                
        //Add e-mail
	$wp_customize->add_setting('anirohotellight_phone', array(
			'default'            => '+123456789',
			'sanitize_callback'  => 'wp_filter_nohtml_kses'
		)
	);
	$wp_customize->add_control('anirohotellight_phone', array(
			'section'  => 'title_tagline',
                        'priority'   => 105,
			'label'    => esc_html__( 'Hotel telephone number:', 'aniro-hotel-light' ),
			'type'     => 'text'
		)
	);                        
                
//Delete "Background Image" section
$wp_customize->remove_section( "background_image" );  
//Delete "Header image" section
$wp_customize->remove_section( "header_image" );  
//Delete "Colors" section
$wp_customize->remove_section( "colors" );         
//Custom Controls
require get_template_directory() . '/inc/customizer/anirohotellight-customizer-custom-controls.php';// phpcs:ignore WPThemeReview.CoreFunctionality.FileInclude.FileIncludeFound  
//Add panel "About anirohotellight"
require get_template_directory() . '/inc/customizer/anirohotellight-customizer-about-theme.php';// phpcs:ignore WPThemeReview.CoreFunctionality.FileInclude.FileIncludeFound 
//Add Panel Front Page Services
require get_template_directory() . '/inc/customizer/anirohotellight-customizer-front-page-services.php';// phpcs:ignore WPThemeReview.CoreFunctionality.FileInclude.FileIncludeFound
//Add panel 'Theme Options'
require get_template_directory() . '/inc/customizer/anirohotellight-customizer-theme-options.php';// phpcs:ignore WPThemeReview.CoreFunctionality.FileInclude.FileIncludeFound        
//Add Panel Header options
require get_template_directory() . '/inc/customizer/anirohotellight-customizer-header-options.php';// phpcs:ignore WPThemeReview.CoreFunctionality.FileInclude.FileIncludeFound 
//Add Panel Google fonts
require get_template_directory() . '/inc/customizer/anirohotellight-customizer-fonts.php';// phpcs:ignore WPThemeReview.CoreFunctionality.FileInclude.FileIncludeFound
//Add Panel Front Page Header
require get_template_directory() . '/inc/customizer/anirohotellight-customizer-front-page-header.php';// phpcs:ignore WPThemeReview.CoreFunctionality.FileInclude.FileIncludeFound
//Add Panel Front Page About
require get_template_directory() . '/inc/customizer/anirohotellight-customizer-front-page-about.php';// phpcs:ignore WPThemeReview.CoreFunctionality.FileInclude.FileIncludeFound
//Add Panel Front Page Rooms
require get_template_directory() . '/inc/customizer/anirohotellight-customizer-front-page-rooms.php';// phpcs:ignore WPThemeReview.CoreFunctionality.FileInclude.FileIncludeFound
//Add Panel Front Page Blog
require get_template_directory() . '/inc/customizer/anirohotellight-customizer-front-page-blog.php';// phpcs:ignore WPThemeReview.CoreFunctionality.FileInclude.FileIncludeFound
//Add Panel Front Page Widget area 2
require get_template_directory() . '/inc/customizer/anirohotellight-customizer-front-page-advertisement.php';// phpcs:ignore WPThemeReview.CoreFunctionality.FileInclude.FileIncludeFound
//Add Panel Front Page testimonials
require get_template_directory() . '/inc/customizer/anirohotellight-customizer-front-page-testimonials.php';// phpcs:ignore WPThemeReview.CoreFunctionality.FileInclude.FileIncludeFound

}
add_action( 'customize_register', 'anirohotellight_customize_register' );



        
/***********************************************************************************
 * Sanitize
***********************************************************************************/
/**
 * Sanitizes checkboxes
 */
function anirohotellight_sanitize_checkbox( $value ) {
    if ( $value == 1 ) {
        return 1;
    } 
    else {
        return '';
    }
}

/**
 * Sanitizes font
 */
function anirohotellight_sanitize_font_header( $value ) {
    	if ($value) {
		$output = strip_tags( stripslashes( $value ) );
	} else {
		$output = 'Muli';
	}
	return $output;
}
/**
 * Sanitizes font
 */
function anirohotellight_sanitize_font_body( $value ) {
    	if ($value) {
		$output = strip_tags( stripslashes( $value ) );
	} else {
		$output = 'Roboto';
	}
	return $output;
}

/**
 * Sanitize layout options
 */
function anirohotellight_sanitize_layout( $value ) {
	if ( !in_array( $value, array( 'sidebar-left', 'sidebar-right', 'no-sidebar' ) ) ) {
		$value = 'sidebar-right';
	}
	return $value;
}
/**
 * Sanitize sections
 */
function anirohotellight_sanitize_section( $value ) {
	if ( !in_array( $value, array( 'services-events', 'services-blog', 'blog-events' ) ) ) {
		$value = 'blog-events';
	}
	return $value;
}
/**
 * Sanitize sections
 */
function anirohotellight_sanitize_posts_number( $value ) {
	if ( !in_array( $value, array( 'show-2', 'show-4' ) ) ) {
		$value = 'show-2';
	}
	return $value;
}

/**
 * Sanitize show footer widgets areas options wor mailchimp widget
 */
function anirohotellight_sanitize_mailchimp_widgets_areas( $value ) {
	if ( !in_array( $value, array( 'on-front-page', 'all-pages', 'not-front-page' ) ) ) {
		$value = 'all-pages';
	}
	return $value;
}

/**
 * Sanitize site title placement
 */
function anirohotellight_sanitize_sitetitle_placement( $value ) {
	if ( !in_array( $value, array( 'top','top-button', 'menu') ) ) {
		$value = 'top';
	}
	return $value;
}

/**
 * Sanitize front page type
 */
function anirohotellight_sanitize_front_page_type( $value ) {
	if ( !in_array( $value, array( 'front-page-type1', 'front-page-type2', 'front-page-type3' ) ) ) {
		$value = 'front-page-type2';
	}
	return $value;
}
/**
 * Sanitize header slider options
 */
function anirohotellight_sanitize_blog_show( $value ) {
	if ( !in_array( $value, array( 'show-1', 'show-2', 'show-3' ) ) ) {
		$value = 'show-2';
	}
	return $value;
}
/**
 * Sanitize header slider options
 */
function anirohotellight_sanitize_blogposts_show( $value ) {
	if ( !in_array( $value, array( 'show-1', 'show-2', 'show-3' ) ) ) {
		$value = 'show-2';
	}
	return $value;
}
/**
 * Sanitize front/home page slider options
 */
function anirohotellight_sanitize_slider_page( $value ) {
	if ( !in_array( $value, array( 'showpage-1', 'showpage-2', 'showpage-3' ) ) ) {
		$value = 'showpage-2';
	}
	return $value;
}

/**
 * Sanitize slider type in header
 */
function anirohotellight_sanitize_slider_type_header( $value ) {
	if ( !in_array( $value, array( 'type-header-1', 'type-header-2' ) ) ) {
		$value = 'type-header-1';
	}
	return $value;
}
/**
 * Sanitize slider type in frontpage/homepage
 */
function anirohotellight_sanitize_slider_type_index( $value ) {
	if ( !in_array( $value, array( 'type-index-1', 'type-index-2' ) ) ) {
		$value = 'type-index-1';
	}
	return $value;
}

/**
 * Info panel
 */
function anirohotellight_sanitize_info_panel( $value ) {
	if ( !in_array( $value, array( 'show-top',  'not-show' ) ) ) {
		$value = 'not-show';
	}
	return $value;
}
/**
 * Book now panel
 */
function anirohotellight_sanitize_booknow_panel( $value ) {
	if ( !in_array( $value, array( 'show-top', 'show-menu', 'not-show' ) ) ) {
		$value = 'not-show';
	}
	return $value;
}
/**
 * Sanitize site title and logo placement - frontpage
 */
function anirohotellight_sanitize_title_placement_frontpage( $value ) {
	if ( !in_array( $value, array( 'center-frontpage', 'left-frontpage' ) ) ) {
		$value = 'center-frontpage';
	}
	return $value;
}
/**
 * Sanitize site title and logo placement
 */
function anirohotellight_sanitize_title_placement( $value ) {
	if ( !in_array( $value, array( 'center', 'left' ) ) ) {
		$value = 'center';
	}
	return $value;
}

/**
 * Sanitize site main menu placement
 */
function anirohotellight_sanitize_menu_placement( $value ) {
	if ( !in_array( $value, array( 'center', 'left') ) ) {
		$value = 'left';
	}
	return $value;
}

/**
 * Sanitize sticky post options
 */

function anirohotellight_sanitize_sticky_post( $value ) {
	if ( !in_array( $value, array( 'square-check', 'square-pin', 'none' ) ) ) {
		$value = 'square-check';
	}
	return $value;
}
/**
 * Sanitize header booking panel
 */
function anirohotellight_sanitize_header_booking_panel( $value ) {
	if ( !in_array( $value, array( 'showright', 'showdown','showcenter' ) ) ) {
		$value = 'showright';
	}
	return $value;
}
/**
 * Sanitize about
 */
function anirohotellight_sanitize_about( $value ) {
	if ( !in_array( $value, array( 'oneline','twoline' ) ) ) {
		$value = 'twoline';
	}
	return $value;
}
/**
 * Sanitize header booking panel
 */
function anirohotellight_sanitize_header_phonenumber( $value ) {
	if ( !in_array( $value, array( 'showtop', 'showdown','notshow' ) ) ) {
		$value = 'showtop';
	}
	return $value;
}
/***********************************************************************************/
function anirohotellight_sanitize_float( $value ) {
    return filter_var($value, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
}

/***********************************************************************************
 * Binds JS handlers to make Theme Customizer preview reload changes asynchronously.
 ***********************************************************************************/
function anirohotellight_customize_preview_js() {
	wp_enqueue_script( 'anirohotellight_customizer', get_template_directory_uri() . '/js/customizer.js', array( 'customize-preview' ), '20151215', true );
}
add_action( 'customize_preview_init', 'anirohotellight_customize_preview_js' );