<?php
/**
 * voltmaster-electrician Theme Customizer
 *
 * @package voltmaster-electrician
 */

 // Custom Controls.
require get_template_directory() . '/inc/custom-control/custom-control.php';

// Sanitize callback.
require get_template_directory() . '/inc/customizer/sanitize-callback.php';

// Default
require get_template_directory() . '/inc/customizer/default.php';

// Load customize sanitize.
include get_template_directory() . '/inc/customizer/active-callback.php';


// Theme section.
// require get_template_directory() . '/inc/customizer/theme-section.php';

/**
 * Add postMessage support for site title and description for the Theme Customizer.
 *
 * @param WP_Customize_Manager $wp_customize Theme Customizer object.
 */
function voltmaster_electrician_customize_register( $wp_customize ) {
	$wp_customize->get_setting( 'blogname' )->transport         = 'postMessage';
	$wp_customize->get_setting( 'blogdescription' )->transport  = 'postMessage';
	$wp_customize->get_setting( 'header_textcolor' )->transport = 'postMessage';

	if ( isset( $wp_customize->selective_refresh ) ) {
		$wp_customize->selective_refresh->add_partial(
			'blogname',
			array(
				'selector'        => '.site-title a',
				'render_callback' => 'voltmaster_electrician_customize_partial_blogname',
			)
		);
		$wp_customize->selective_refresh->add_partial(
			'blogdescription',
			array(
				'selector'        => '.site-description',
				'render_callback' => 'voltmaster_electrician_customize_partial_blogdescription',
			)
		);
	}
	// Front Page Link
	require get_template_directory() . '/inc/customizer/home-section.php';

	require get_template_directory() . '/inc/customizer/section-pro.php';

	// Theme Page Link
	require get_template_directory() . '/inc/customizer/theme-options.php';
}
add_action( 'customize_register', 'voltmaster_electrician_customize_register' );

/**
 * Render the site title for the selective refresh partial.
 *
 * @return void
 */
function voltmaster_electrician_customize_partial_blogname() {
	bloginfo( 'name' );
}

/**
 * Render the site tagline for the selective refresh partial.
 *
 * @return void
 */
function voltmaster_electrician_customize_partial_blogdescription() {
	bloginfo( 'description' );
}

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

/**
 *
 */
function voltmaster_electrician_customize_backend_scripts() {

	wp_enqueue_style( 'voltmaster-electrician-fontawesome-all', get_template_directory_uri() . '/assets/css/all.css' );

	wp_enqueue_style( 'voltmaster-electrician-main-css', get_template_directory_uri() . '/assets/css/output.css' );

	wp_enqueue_style( 'voltmaster-electrician-admin-customizer-style', get_template_directory_uri() . '/inc/customizer/css/customizer-style.css' );

	// Enqueue main customizer JS
	wp_enqueue_script(
		'voltmaster-electrician-admin-customizer',
		get_template_directory_uri() . '/inc/customizer/js/customizer-script.js',
		array( 'jquery', 'customize-controls' ),
		'20151215',
		true
	);

	// Enqueue the controls script
	wp_enqueue_script(
		'voltmaster-electrician-admin-customizer-control',
		get_template_directory_uri() . '/inc/customizer/js/customize-controls.js',
		array( 'jquery', 'customize-controls' ),
		'1.0',
		true
	);

	// Fix: Localize the customizer params for use in JS
	wp_localize_script(
		'voltmaster-electrician-admin-customizer-control',
		'voltmaster_electrician_customizer_params',
		array(
			'ajaxurl' => admin_url( 'admin-ajax.php' ),
		)
	);
}
add_action( 'customize_controls_enqueue_scripts', 'voltmaster_electrician_customize_backend_scripts', 10 );

/**
 * Enqueue the stylesheet.
 */
function voltmaster_electrician_customizer_stylesheet() {

    wp_register_style( 'voltmaster-electrician-admin-css', get_template_directory_uri() . '/inc/customizer/css/customize-controls.css', NULL, NULL, 'all' );
    wp_enqueue_style( 'voltmaster-electrician-admin-css' );
}
add_action( 'customize_controls_print_styles', 'voltmaster_electrician_customizer_stylesheet' );

///////////////////////////// customize  color 


function voltmaster_electrician_customize_css() {
    $custom_css = "
        #site-navigation .btn a {
            background-color: " . esc_html(get_theme_mod('header_buttonbg_color')) . ";
        }
        #site-navigation .btn a {
            color: " . esc_html(get_theme_mod('header_buttontext_color')) . ";
        }
        .section-header .container .flex svg{
            color: " . esc_html(get_theme_mod('info_icon_color')) . "!important;
        }
        .section-header .container .flex a{
            color: " . esc_html(get_theme_mod('info_text_color')) . "!important;
        }
        .section-header .container .flex span{
            color: " . esc_html(get_theme_mod('emergency_text_color')) . ";
        }
        .section-header .container .call-content .grid a{
            color: " . esc_html(get_theme_mod('callus_text_color')) . "!important;
        }
        .widget .wp-block-heading{
            color: " . esc_html(get_theme_mod('heading_text_color')) . ";
        } 
        .widget .wp-block-heading{
            background-color: " . esc_html(get_theme_mod('heading_bg_color')) . ";
        }
        .sidebar-div .wp-block-latest-posts__list li a, .sidebar-div .wp-block-archives-list li a, .sidebar-div .wp-block-categories-list li a, .single_sidebar .wp-block-latest-posts__list li a, .single_sidebar .wp-block-archives-list li a, .single_sidebar .wp-block-categories-list li a, .widget_recent_entries li a, .widget_categories li a, #secondary ul li a, .widget_archive p, .widget_archive select, .widget ul li a {
            color: " . esc_html(get_theme_mod('text_color')) . ";
        }
        #primary .widget ul li a::before{
            color: " . esc_html(get_theme_mod('text_icon_color')) . ";
        }
        .widget.widget_search .wp-block-search__inside-wrapper .wp-block-search__button{
            color: " . esc_html(get_theme_mod('search_text_color')) . ";
        }   
        .widget.widget_search .wp-block-search__inside-wrapper .wp-block-search__button{
            background-color: " . esc_html(get_theme_mod('search_bg_color')) . "!important;
        }
        .post-date a{
            color: " . esc_html(get_theme_mod('date_text_color')) . ";
        }
        .maincontent .entry-container a{
            color: " . esc_html(get_theme_mod('title_text_color')) . ";
        }
        .maincontent .post-item p {
            color: " . esc_html(get_theme_mod('post_text_color')) . ";
        }
        .maincontent .post-item p a.readbtn{
            color: " . esc_html(get_theme_mod('post_readmore_text_color')) . ";
        }                       
        .slider-inner-mainbox .slider-socialicon .socialicon {
            color: " . esc_html(get_theme_mod('social_icon_color')) . ";
        }
        #featured-slider .entry-container h4 {
            color: " . esc_html(get_theme_mod('slider_title_color')) . ";
        }
        #featured-slider .entry-container .content {
            color: " . esc_html(get_theme_mod('slider_subtitle_color')) . ";
        }
        #primary-menu, .custom-menu-wrapper{
            background-color: " . esc_html(get_theme_mod('menu_bg_color')) . ";
        }
        #featured-slider .content a,
        #featured-slider code,
        .wp-block-buttons .wp-block-button__link,
        .singlepage #submit {
            background: " . esc_html(get_theme_mod('slider_readmore_color')) . ";
            color: " . esc_html(get_theme_mod('slider_readmoretxt_color')) . " !important;
        }
        #featured-slider .slick-dots li {
            background: " . esc_html(get_theme_mod('slider_slickdot_color')) . ";
        }
        #featured-slider .slick-dots li.slick-active {
            background: " . esc_html(get_theme_mod('slider_activeslickdot_color')) . ";
        }
        #featured-slider .sliderbut1 a {
            color: " . esc_html(get_theme_mod('slider_buttontext1_color')) . ";
        }
        #featured-slider .rounded1 {
            background: " . esc_html(get_theme_mod('voltmaster_electrician_callnow_btn_bgcolor')) . ";
        }
        #featured-slider .rounded1 {
            color: " . esc_html(get_theme_mod('voltmaster_electrician_callnow_btn_textcolor')) . ";
        }
        #featured-slider .rounded2{
           color: " . esc_html(get_theme_mod('voltmaster_electrician_getfree_btn_textcolor')) . ";
        }
        #featured-slider .header h3{
            color: " . esc_html(get_theme_mod('voltmaster_electrician_heading_textcolor')) . ";
        }
        #featured-slider .wrapper h2.entry-title{
            color: " . esc_html(get_theme_mod('voltmaster_electrician_subheading_textcolor')) . ";
        }          
           
        #featured-slider .sliderbut2 a {
            color: " . esc_html(get_theme_mod('slider_buttontext2_color')) . ";
        }
        #featured-slider .sliderbut2 {
            background: " . esc_html(get_theme_mod('slider_buttonbg2_color')) . ";
        }
        #featured-slider .rating svg{
            color: " . esc_html(get_theme_mod('voltmaster_electrician_ratingstar_color')) . "!important;
        }  
        .featured-whatweoffer {
            background: " . esc_html(get_theme_mod('whatweoffer_background_color')) . ";
        }
        .featured-whatweoffer .head-title {
            color: " . esc_html(get_theme_mod('whatweoffer_title_color')) . ";
        }
        .featured-whatweoffer .head-subtitle {
            color: " . esc_html(get_theme_mod('whatweoffer_subtitle_color')) . ";
        }
        .featured-whatweoffer .title a {
            color: " . esc_html(get_theme_mod('whatweoffer_cardtitle_color')) . ";
        }
    ";

    // Ensure the main stylesheet is enqueued first
    wp_enqueue_style('voltmaster-electrician-style', get_stylesheet_uri());

    // Add inline CSS to it
    wp_add_inline_style('voltmaster-electrician-style', $custom_css);
}
add_action('wp_enqueue_scripts', 'voltmaster_electrician_customize_css');
