<?php
/**
 * Load scripts
 *
 * @package wpstream-theme
 */

add_action( 'wp_enqueue_scripts', 'wpstream_theme_enqueue_scripts', 1000 );
/**
 * Theme enqueue scripts
 */
function wpstream_theme_enqueue_scripts() {
	$suffix  = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';

	wp_enqueue_script( 'jquery' );
	// Check if the current page is a singular page.
	if ( is_singular() ) {
		// Enqueue FancyBox scripts and styles only when the condition is met.
		wp_enqueue_script( 'fancybox', trailingslashit( get_template_directory_uri() ) . 'fancybox/jquery.fancybox.pack.js', array( 'jquery' ), '1.0', true );
		wp_enqueue_style( 'fancybox', trailingslashit( get_template_directory_uri() ) . 'fancybox/jquery.fancybox.css', array(), '1.0', 'all' );
	}

	wp_enqueue_script( 'wpstream-theme-scripts', trailingslashit( get_template_directory_uri() ) . 'js/wpstream-theme-script.js', array( 'jquery' ), '1.0', true );

	wp_localize_script(
		'wpstream-theme-scripts',
		'wpstreamThemeScriptsVars',
		array(
			'ajaxurl' 				=> 	admin_url( 'admin-ajax.php' ), // WordPress AJAX URL.
			'processing'			=>	esc_html('sending...','hello-wpstream'),
			'send_mess' 			=>  esc_html__('Send Message','hello-wpstream'),
			'is_user_logged_in' 	=> 	is_user_logged_in() ? '1' : '0',
			'comment_text_empty' 	=>  esc_html__('Please type your comment.','hello-wpstream'),
			'comment_author_empty' 	=> 	esc_html__('Please enter your name.', 'hello-wpstream'),
            'comment_email_empty' 	=> 	esc_html__('Please enter your email.', 'hello-wpstream'),
			'comment_email_invalid' => esc_html__('Please enter a valid email address.', 'hello-wpstream'),
			'gdpr_agree' 			=> esc_html__('You need to agree with GDPR terms.', 'hello-wpstream'),
		)
	);

	if ( wpstream_is_dashboard_page() ) {
		wp_enqueue_style( 'select2-css', trailingslashit( get_template_directory_uri() ) ."css/select2{$suffix}.css", array(), '4.1.0-rc.0' );
		wp_enqueue_style( 'select2-bootstrap-5-theme-css', trailingslashit( get_template_directory_uri() ) . "css/select2-bootstrap-5-theme{$suffix}.css", array(), '1.3.0' );

		// Scripts.
		wp_enqueue_script( 'select2-js',  trailingslashit( get_template_directory_uri() )."js/select2{$suffix}.js", array( 'jquery' ), '4.1.0-rc.0', true );
		wp_enqueue_script( 'jquery-ui-autocomplete' );
		wp_enqueue_style( 'jquery-ui', trailingslashit( get_template_directory_uri() ).'css/jquery-ui.css', array(), '1.0', 'all' );
	}
}