<?php

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

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

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

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

} );

 /**
 * Enqueue scripts and styles.
 */
function automotive_services_scripts() {
	
	// Styles	 
	
	wp_enqueue_style('owl-carousel-min',get_template_directory_uri().'/assets/css/owl.carousel.min.css');

	wp_enqueue_style('bootstrap-min',get_template_directory_uri().'/assets/css/bootstrap.min.css');
	
	wp_enqueue_style('automotive-services-editor-style',get_template_directory_uri().'/assets/css/editor-style.css');

	wp_enqueue_style('automotive-services-main', get_template_directory_uri() . '/assets/css/main.css');

	wp_enqueue_style('automotive-services-woo', get_template_directory_uri() . '/assets/css/woo.css');

	wp_enqueue_style( 'font-awesome', get_template_directory_uri().'/assets/css/fontawesome-all.css' );

	
	wp_enqueue_style( 'automotive-services-style', get_stylesheet_uri() );

    wp_enqueue_style('automotive-services-main', get_stylesheet_uri(), array() );
    wp_style_add_data('automotive-services-main', 'rtl', 'replace');
	
	// Scripts

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

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

	wp_enqueue_script('owl-carousel', get_template_directory_uri() . '/assets/js/owl.carousel.min.js', array('jquery'), false, true);

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

    // Animations
    if ( get_theme_mod( 'automotive_services_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', 'automotive_services_scripts' );


// Function to enqueue custom CSS
function automotive_services_enqueue_custom_css() {
    // Define a unique handle for your inline stylesheet
    $handle = 'automotive-services-style';
    
    // Get the generated custom CSS
    $automotive_services_custom_css = "";

    $automotive_services_blog_layouts = get_theme_mod('automotive_services_blog_layout_option_setting', 'Default');
    if ($automotive_services_blog_layouts == 'Default') {
        $automotive_services_custom_css .= '.blog-item{';
        $automotive_services_custom_css .= 'text-align:center;';
        $automotive_services_custom_css .= '}';
    } elseif ($automotive_services_blog_layouts == 'Left') {
        $automotive_services_custom_css .= '.blog-item{';
        $automotive_services_custom_css .= 'text-align:Left;';
        $automotive_services_custom_css .= '}';
    } elseif ($automotive_services_blog_layouts == 'Right') {
        $automotive_services_custom_css .= '.blog-item{';
        $automotive_services_custom_css .= 'text-align:Right;';
        $automotive_services_custom_css .= '}';
    }

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

    // Add inline style for Scroll to Top
    $automotive_services_scroll_top_bg_color = get_theme_mod('automotive_services_scroll_top_bg_color', '#D1133D');
    $automotive_services_scroll_top_color = get_theme_mod('automotive_services_scroll_top_color', '#fff');

    // Use global if still default
    if ( $automotive_services_scroll_top_bg_color === '#D1133D' ) {
        $automotive_services_scroll_top_bg_color = get_theme_mod('automotive_services_dynamic_color_one');
    }

    $automotive_services_scroll_custom_css = "
        #scrolltop {
            background-color: {$automotive_services_scroll_top_bg_color};
        }
        #scrolltop span {
            color: {$automotive_services_scroll_top_color};
        }
    ";
    wp_add_inline_style('automotive-services-style', $automotive_services_scroll_custom_css);

    // Add inline style for Preloader
    $automotive_services_preloader_bg_color = get_theme_mod('automotive_services_preloader_bg_color', '#ffffff');
    $automotive_services_preloader_color = get_theme_mod('automotive_services_preloader_color', '#D1133D');

    // Use global if still default
    if ( $automotive_services_preloader_color === '#D1133D' ) {
        $automotive_services_preloader_color = get_theme_mod('automotive_services_dynamic_color_one');
    }

    $automotive_services_preloader_custom_css = "
        .loading {
            background-color: {$automotive_services_preloader_bg_color};
        }
        .loader {
            border-color: {$automotive_services_preloader_color};
            color: {$automotive_services_preloader_color};
            text-shadow: 0 0 10px {$automotive_services_preloader_color};
        }
        .loader::before {
            border-top-color: {$automotive_services_preloader_color};
            border-right-color: {$automotive_services_preloader_color};
        }
        .loader span::before {
            background: {$automotive_services_preloader_color};
            box-shadow: 0 0 10px {$automotive_services_preloader_color};
        }
    ";
    wp_add_inline_style('automotive-services-style', $automotive_services_preloader_custom_css);

    // inlin css
    $automotive_services_inline_style = '';

    $automotive_services_slider_setting = get_theme_mod( 'automotive_services_slider_setting', false);
    if($automotive_services_slider_setting == false) {
        $automotive_services_inline_style .= '.page-template-template-frontpage .header-main{';
        $automotive_services_inline_style .= 'position:static; border-bottom:1px solid #ccc;';
        $automotive_services_inline_style .= '}';
        $automotive_services_inline_style .= '.page-template-template-frontpage .main-header .navbar .navbar-menu ul li a{';
        $automotive_services_inline_style .= 'color:#000;';
        $automotive_services_inline_style .= '}';
        $automotive_services_inline_style .= '.main-header .navbar .navbar-menu li.current_page_item a{';
        $automotive_services_inline_style .= 'color:#fff !important;';
        $automotive_services_inline_style .= '}';
        $automotive_services_inline_style .= '.page-template-template-frontpage .main-header .navbar .navbar-menu ul ul li a{';
        $automotive_services_inline_style .= 'color:#fff;';
        $automotive_services_inline_style .= '}';
    }

    wp_add_inline_style( 'automotive-services-style', $automotive_services_inline_style );
}

// Hook the function to the 'wp_enqueue_scripts' action
add_action('wp_enqueue_scripts', 'automotive_services_enqueue_custom_css');