<?php

// Load the JS and CSS.
add_action( 'customize_controls_enqueue_scripts', function() {

	$version = wp_get_theme()->get( 'Version' );

	wp_enqueue_script(
		'led-tv-customize-section-button',
		get_theme_file_uri( 'assets/js/customize-controls.js' ),
		[ 'customize-controls' ],
		$version,
		true
	);
	wp_localize_script(
		'led-tv-customize-section-button',
		'led_tv_customizer_params',
		array(
			'ajaxurl' =>	admin_url( 'admin-ajax.php' )
		)
	);

	wp_enqueue_style(
		'led-tv-customize-section-button',
		get_theme_file_uri( 'assets/css/customize-controls.css' ),
		[ 'customize-controls' ],
 		$version
	);

} );

 /**
 * Enqueue scripts and styles.
 */
function led_tv_scripts() {
	
	// Styles	 

	wp_enqueue_style('all-min',get_template_directory_uri().'/assets/css/all.min.css');

	wp_enqueue_style('bootstrap-min',get_template_directory_uri().'/assets/css/bootstrap.min.css');
		
	wp_enqueue_style('font-awesome',get_template_directory_uri().'/assets/css/fonts/font-awesome/css/font-awesome.min.css');
	
	wp_enqueue_style('led-tv-editor-style',get_template_directory_uri().'/assets/css/editor-style.css');

	wp_enqueue_style('led-tv-main', get_template_directory_uri() . '/assets/css/main.css');

	wp_enqueue_style('led-tv-woo', get_template_directory_uri() . '/assets/css/woo.css');
	
	wp_enqueue_style( 'led-tv-style', get_stylesheet_uri() );

	wp_enqueue_style('led-tv-main', get_stylesheet_uri(), array() );
		wp_style_add_data('led-tv-main', 'rtl', 'replace');

	// Define a unique handle for your inline stylesheet
	$handle = 'led-tv-style';
    
	// Get the generated custom CSS
	$led_tv_custom_css = "";

	$led_tv_blog_layouts = get_theme_mod('led_tv_blog_layout_option_setting', 'Default');
	if ($led_tv_blog_layouts == 'Default') {
		$led_tv_custom_css .= '.blog-item{';
		$led_tv_custom_css .= 'text-align:center;';
		$led_tv_custom_css .= '}';
	} elseif ($led_tv_blog_layouts == 'Left') {
		$led_tv_custom_css .= '.blog-item{';
		$led_tv_custom_css .= 'text-align:Left;';
		$led_tv_custom_css .= '}';
	} elseif ($led_tv_blog_layouts == 'Right') {
		$led_tv_custom_css .= '.blog-item{';
		$led_tv_custom_css .= 'text-align:Right;';
		$led_tv_custom_css .= '}';
	}

	// Enqueue the inline stylesheet
	wp_add_inline_style($handle, $led_tv_custom_css);

	// Add inline style for Scroll to Top
    $led_tv_scroll_top_bg_color = get_theme_mod('led_tv_scroll_top_bg_color', '#01b9ef');
    $led_tv_scroll_top_color = get_theme_mod('led_tv_scroll_top_color', '#fff');

	// Use global if still default
    if ( $led_tv_scroll_top_bg_color === '#01b9ef' ) {
        $led_tv_scroll_top_bg_color = get_theme_mod('led_tv_dynamic_color_one');
    }

    $led_tv_scroll_custom_css = "
        #scrolltop {
            background-color: {$led_tv_scroll_top_bg_color};
        }
        #scrolltop span {
            color: {$led_tv_scroll_top_color};
        }
    ";
    wp_add_inline_style('led-tv-style', $led_tv_scroll_custom_css);

    // Add inline style for Preloader
    $led_tv_preloader_bg_color = get_theme_mod('led_tv_preloader_bg_color', '#ffffff');
    $led_tv_preloader_color = get_theme_mod('led_tv_preloader_color', '#01b9ef');

	// Use global if still default
    if ( $led_tv_preloader_color === '#01b9ef' ) {
        $led_tv_preloader_color = get_theme_mod('led_tv_dynamic_color_one');
    }

    $led_tv_preloader_custom_css = "
        .loading {
            background-color: {$led_tv_preloader_bg_color};
        }
        .loader {
            border-color: {$led_tv_preloader_color};
            color: {$led_tv_preloader_color};
            text-shadow: 0 0 10px {$led_tv_preloader_color};
        }
        .loader::before {
            border-top-color: {$led_tv_preloader_color};
            border-right-color: {$led_tv_preloader_color};
        }
        .loader span::before {
            background: {$led_tv_preloader_color};
            box-shadow: 0 0 10px {$led_tv_preloader_color};
        }
    ";
    wp_add_inline_style('led-tv-style', $led_tv_preloader_custom_css);
	
	// Scripts

	wp_enqueue_script('bootstrap', get_template_directory_uri() . '/assets/js/bootstrap.bundle.min.js', array('jquery'), false, true);

	wp_enqueue_script('led-tv-theme-js', get_template_directory_uri() . '/assets/js/theme.js', array('jquery'), false, true);

	if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
		wp_enqueue_script( 'comment-reply' );
	}

    // Animations
    if ( get_theme_mod( 'led_tv_animation_enabled', true ) ) {
        wp_enqueue_script('wow-js', get_theme_file_uri('/assets/js/wow.js'), array('jquery'), null, true);
        wp_enqueue_style('animate-css', get_template_directory_uri() . '/assets/css/animate.css');
    }
}
add_action( 'wp_enqueue_scripts', 'led_tv_scripts' );