<?php
/**
 * computer-repair-solutions Theme Customizer
 *
 * @package computer-repair-solutions
 */

 // 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 computer_repair_solutions_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' => 'computer_repair_solutions_customize_partial_blogname',
			)
		);
		$wp_customize->selective_refresh->add_partial(
			'blogdescription',
			array(
				'selector'        => '.site-description',
				'render_callback' => 'computer_repair_solutions_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', 'computer_repair_solutions_customize_register' );

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

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

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

/**
 *
 */
function computer_repair_solutions_customize_backend_scripts() {

	wp_enqueue_style( 'computer-repair-solutions-fontawesome-all', get_template_directory_uri() . '/assets/css/all.css' );

	wp_enqueue_style( 'computer-repair-solutions-main-css', get_template_directory_uri() . '/assets/css/output.css' );

	wp_enqueue_style( 'computer-repair-solutions-admin-customizer-style', get_template_directory_uri() . '/inc/customizer/css/customizer-style.css' );

	// Enqueue main customizer JS
	wp_enqueue_script(
		'computer-repair-solutions-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(
		'computer-repair-solutions-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(
		'computer-repair-solutions-admin-customizer-control',
		'computer_repair_solutions_customizer_params',
		array(
			'ajaxurl' => admin_url( 'admin-ajax.php' ),
		)
	);
}
add_action( 'customize_controls_enqueue_scripts', 'computer_repair_solutions_customize_backend_scripts', 10 );

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

    wp_register_style( 'computer-repair-solutions-admin-css', get_template_directory_uri() . '/inc/customizer/css/customize-controls.css', NULL, NULL, 'all' );
    wp_enqueue_style( 'computer-repair-solutions-admin-css' );
}
add_action( 'customize_controls_print_styles', 'computer_repair_solutions_customizer_stylesheet' );

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


function computer_repair_solutions_customize_css() {
    
    $custom_css = "
        .section-header .bg-dark{
			 background: " . esc_html(get_theme_mod('topheader_bg_color')) . "!important;
		}
		#site-navigation .btn a{
			background-color: " . esc_html(get_theme_mod('button_bg_color')) . ";
		}
		#site-navigation .btn a{
			color: " . esc_html(get_theme_mod('button_text_color')) . ";
		}
		#site-navigation ul li a{
			color: " . esc_html(get_theme_mod('menu_text_color')) . ";
		}
		.widget_block h2{
			background-color: " . esc_html(get_theme_mod('Sidebar_heading_bg_color')) . ";
		}	
    ";


    // Ensure the main stylesheet is enqueued first
    wp_enqueue_style('computer-repair-solutions-style', get_stylesheet_uri());

    // Add inline CSS to it
    wp_add_inline_style('computer-repair-solutions-style', $custom_css);
}
add_action('wp_enqueue_scripts', 'computer_repair_solutions_customize_css');
