<?php

// Prevent Direct Access
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

// ---------- Frontend Resources

function maxo_add_resources(){

	$theme_version = wp_get_theme()->get('Version');
	$ltr = is_rtl() ? '' : '-ltr';

	// Styles
	if( is_rtl() ){
		wp_enqueue_style('maxo-primary-font', get_theme_file_uri('assets/css/font/primary-'.maxo_get_option('primary_font', 'iran-yekan').'.css'), array(), $theme_version);
		wp_enqueue_style('maxo-secondary-font', get_theme_file_uri('assets/css/font/secondary-'.maxo_get_option('secondary_font', 'aviny').'.css'), array(), $theme_version);

		if( current_user_can('read') ){
			wp_enqueue_style('maxo-admin-font', get_theme_file_uri('assets/css/font/admin-iran-yekan.css'), array(), $theme_version);
		}
	}
	else{
		wp_enqueue_style('maxo-primary-font', get_theme_file_uri('assets/css-ltr/font/primary-'.maxo_get_option('primary_font_ltr', 'lato').'.css'), array(), $theme_version);
		wp_enqueue_style('maxo-secondary-font', get_theme_file_uri('assets/css-ltr/font/secondary-'.maxo_get_option('secondary_font_ltr', 'lato').'.css'), array(), $theme_version);
	}
	wp_enqueue_style('maxo-bootstrap', get_theme_file_uri('assets/css'.$ltr.'/bootstrap.min.css'), array(), $theme_version);
	wp_enqueue_style('maxo-font-awesome', get_theme_file_uri('assets/css/font-awesome.min.css'), array(), $theme_version);
	wp_enqueue_style('maxo-animate', get_theme_file_uri('assets/css/animate.css'), array(), $theme_version);
	wp_enqueue_style('maxo-cubeportfolio', get_theme_file_uri('assets/css/cubeportfolio.min.css'), array(), $theme_version);
	wp_enqueue_style('maxo-fancybox', get_theme_file_uri('assets/css/jquery.fancybox.min.css'), array(), $theme_version);
	wp_enqueue_style('maxo-swiper', get_theme_file_uri('assets/css/swiper.min.css'), array(), $theme_version);
	wp_enqueue_style('maxo-settings', get_theme_file_uri('assets/css'.$ltr.'/settings.css'), array(), $theme_version);
	wp_enqueue_style('maxo-bootsnav', get_theme_file_uri('assets/css'.$ltr.'/bootsnav.css'), array(), $theme_version);
	wp_enqueue_style('maxo-styles', get_theme_file_uri('assets/css'.$ltr.'/style.css'), array(), $theme_version);

	// Scripts
	wp_enqueue_script('jquery');

	if( is_front_page() && get_theme_mod('contact_map_display', true) && get_theme_mod('contact_map_iframe', '') == '' ){
		wp_enqueue_script('maxo-google-maps', 'https://maps.google.com/maps/api/js?key='.get_theme_mod('contact_map_api', '').'&language='.get_locale(), array(), null, true);
		wp_enqueue_script('maxo-map', get_theme_file_uri('assets/js/map.js'), array(), $theme_version, true);
	}

	wp_enqueue_script('maxo-bootstrap', get_theme_file_uri('assets/js'.$ltr.'/bootstrap.min.js'), array(), $theme_version, true);
	wp_enqueue_script('maxo-bootsnav', get_theme_file_uri('assets/js/bootsnav.js'), array(), $theme_version, true);
	wp_enqueue_script('maxo-jquery-easing', get_theme_file_uri('assets/js/jquery.easing.min.js'), array(), $theme_version, true);
	wp_enqueue_script('maxo-swiper', get_theme_file_uri('assets/js/swiper.min.js'), array(), $theme_version, true);
	wp_enqueue_script('maxo-cubeportfolio', get_theme_file_uri('assets/js/jquery.cubeportfolio.min.js'), array(), $theme_version, true);
	wp_enqueue_script('maxo-matchHeight', get_theme_file_uri('assets/js/jquery.matchHeight-min.js'), array(), $theme_version, true);
	wp_enqueue_script('maxo-fancybox', get_theme_file_uri('assets/js/jquery.fancybox.min.js'), array(), $theme_version, true);
	wp_enqueue_script('maxo-parallax', get_theme_file_uri('assets/js/jquery.parallax-1.1.3.js'), array(), $theme_version, true);
	wp_enqueue_script('maxo-themepunch-tools', get_theme_file_uri('assets/js/jquery.themepunch.tools.min.js'), array(), $theme_version, true);
	wp_enqueue_script('maxo-themepunch-revolution', get_theme_file_uri('assets/js/jquery.themepunch.revolution.min.js'), array(), $theme_version, true);
	wp_enqueue_script('maxo-rev-ext-actions', get_theme_file_uri('assets/js/revolution.extension.actions.min.js'), array(), $theme_version, true);
	wp_enqueue_script('maxo-rev-ext-layeranimation', get_theme_file_uri('assets/js/revolution.extension.layeranimation.min.js'), array(), $theme_version, true);
	wp_enqueue_script('maxo-rev-ext-navigation', get_theme_file_uri('assets/js/revolution.extension.navigation.min.js'), array(), $theme_version, true);
	wp_enqueue_script('maxo-rev-ext-parallax', get_theme_file_uri('assets/js/revolution.extension.parallax.min.js'), array(), $theme_version, true);
	wp_enqueue_script('maxo-rev-ext-slideanims', get_theme_file_uri('assets/js/revolution.extension.slideanims.min.js'), array(), $theme_version, true);
	wp_enqueue_script('maxo-functions', get_theme_file_uri('assets/js/functions.js'), array(), $theme_version, true);

	// Scripts Translations
	wp_add_inline_script( 'maxo-functions', 'const $translations = ' . json_encode( [
		'form_field_required' => esc_html__('This field is required', 'maxo-fa'),
		'form_email_required' => esc_html__('The email is required', 'maxo-fa'),
		'form_email_invalid' => esc_html__('Please enter a valid email', 'maxo-fa'),
	], JSON_UNESCAPED_UNICODE ), 'before' );
}

add_action('wp_enqueue_scripts', 'maxo_add_resources');

// ---------- Admin Resources

function maxo_admin_style(){

	$theme_version = wp_get_theme()->get( 'Version' );
	$ltr = is_rtl() ? '' : '-ltr';

	if( is_rtl() ){
		wp_enqueue_style('maxo-admin-font', get_theme_file_uri('assets/css/font/admin-iran-yekan.css'), array(), $theme_version);
	}

	wp_enqueue_style('maxo-admin-styles', get_theme_file_uri('assets/css'.$ltr.'/admin.css'), array(), $theme_version);
}

add_action('admin_enqueue_scripts', 'maxo_admin_style');
add_action('login_enqueue_scripts', 'maxo_admin_style');
add_action('elementor/editor/after_enqueue_styles', 'maxo_admin_style');
