<?php
 /**
 * Enqueue scripts and styles.
 */
function education_skill_development_scripts() {
	
	// Styles

	wp_enqueue_style('dashicons' );

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

	wp_enqueue_style('owl-carousel',get_template_directory_uri().'/css/owl.carousel.css');
	
	wp_enqueue_style('font-awesome',get_template_directory_uri().'/css/fonts/font-awesome/css/font-awesome.min.css');
	
	wp_enqueue_style('education-skill-development-widget',get_template_directory_uri().'/css/widget.css');
	
	wp_enqueue_style('education-skill-development-color-default',get_template_directory_uri().'/css/colors/default.css');
	
	wp_enqueue_style('education-skill-development-wp-test',get_template_directory_uri().'/css/wp-test.css');
	
	wp_enqueue_style('education-skill-development-menu',get_template_directory_uri().'/css/menu.css');
	
	wp_enqueue_style('education-skill-development-style', get_stylesheet_uri() );

	wp_style_add_data('education-skill-development-style', 'rtl', 'replace');
	
	wp_enqueue_style('education-skill-development-gutenberg',get_template_directory_uri().'/css/gutenberg.css');
	
	wp_enqueue_style('education-skill-development-responsive',get_template_directory_uri().'/css/responsive.css');
	
	// Scripts
	wp_enqueue_script('jquery-ui-core');
	
	wp_enqueue_script('bootstrap', get_template_directory_uri() . '/js/bootstrap.min.js', array('jquery'), '4.3.1', true); 

	wp_enqueue_script('owl-carousel', get_template_directory_uri() . '/js/owl.carousel.js', array('jquery'), true); 
	
	wp_register_script('education-skill-development-custom-js', get_template_directory_uri() . '/js/custom.js', array('jquery'), false, true);

	wp_localize_script('education-skill-development-custom-js', 'education_skill_development_script_args',
		array( 
			'scroll_top_type' => get_theme_mod( 'education_skill_development_scroll_to_top_type' ) == 'simple-scroll' ? 'simple-scroll' : 'advanced-scroll'
		)
	);
	wp_enqueue_script('education-skill-development-custom-js');

	wp_enqueue_script('education-skill-development-navigation-focus', get_template_directory_uri() . '/js/navigation-focus.js', array(), true );

	wp_enqueue_script('skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20151215', true );

		if ( get_theme_mod( 'education_skill_development_animation_enabled', true ) ) {
		wp_enqueue_script(
			'education-skill-development-wow-script',
			get_template_directory_uri() . '/js/wow.js',
			array( 'jquery' ),
			'1.0',
			true
		);

		wp_enqueue_style(
			'education-skill-development-animate',
			get_template_directory_uri() . '/css/animate.css',
			array(),
			'4.1.1'
		);
	}

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

	require get_template_directory(). '/inc/common-inline.php';

	wp_add_inline_style( 'education-skill-development-style',$education_skill_development_common_inline_css );
}
add_action( 'wp_enqueue_scripts', 'education_skill_development_scripts' );

//Admin Enqueue for Admin
function education_skill_development_admin_enqueue_scripts(){	
	wp_enqueue_style('education-skill-development-style-customizer',get_template_directory_uri(). '/css/style-customizer.css');

	wp_enqueue_style( 'education-skill-development-admin-style', get_template_directory_uri().'/inc/started/main.css' );

	wp_enqueue_script( 'education-skill-development-admin-script', get_template_directory_uri() . '/inc/admin-notice/admin.js', array( 'jquery' ), '', true );
}
add_action( 'admin_enqueue_scripts', 'education_skill_development_admin_enqueue_scripts' );

// Fix for Customizer querySelector error with numeric menu IDs and invalid pseudo-selectors
function education_skill_development_customize_controls_fix() {
	$fix_script = "
	(function() {
		var selectorErrors = {};
		
		// Override document.querySelector to fix invalid selectors
		var originalQuerySelector = document.querySelector;
		document.querySelector = function(selector) {
			if (typeof selector === 'string') {
				var originalSelector = selector;
				
				// Fix selectors with numeric IDs in brackets: #accordion-section-nav_menu[180]
				if (selector.match(/\\[\\d+\\]$/)) {
					selector = selector.replace(/\\[(\\d+)\\]$/, '-\$1');
				}
				
				// Fix invalid pseudo-selectors: :last should be :last-child
				if (selector.indexOf(':last') !== -1 && selector.indexOf(':last-child') === -1 && selector.indexOf(':last-of-type') === -1) {
					selector = selector.replace(/:last(\\s|,|$)/g, ':last-child\$1');
				}
			}
			try {
				return originalQuerySelector.call(this, selector);
			} catch(e) {
				// Only log if this is the first time seeing this error
				if (!selectorErrors[selector]) {
					selectorErrors[selector] = true;
					console.warn('Education Skill Development - querySelector fixed selector issue:', selector);
				}
				return null;
			}
		};
		
		// Also override querySelectorAll
		var originalQuerySelectorAll = document.querySelectorAll;
		document.querySelectorAll = function(selector) {
			if (typeof selector === 'string') {
				var originalSelector = selector;
				
				// Fix selectors with numeric IDs in brackets
				if (selector.match(/\\[\\d+\\]$/)) {
					selector = selector.replace(/\\[(\\d+)\\]$/, '-\$1');
				}
				
				// Fix invalid pseudo-selectors: :last should be :last-child
				if (selector.indexOf(':last') !== -1 && selector.indexOf(':last-child') === -1 && selector.indexOf(':last-of-type') === -1) {
					selector = selector.replace(/:last(\\s|,|$)/g, ':last-child\$1');
				}
			}
			try {
				return originalQuerySelectorAll.call(this, selector);
			} catch(e) {
				// Only log if this is the first time seeing this error
				if (!selectorErrors[selector]) {
					selectorErrors[selector] = true;
					console.warn('Education Skill Development - querySelectorAll fixed selector issue:', selector);
				}
				return [];
			}
		};
	})();
	";
	wp_add_inline_script( 'customize-base', $fix_script, 'before' );
}
add_action( 'customize_controls_enqueue_scripts', 'education_skill_development_customize_controls_fix', 0 );

?>