<?php

namespace Gigneo;

if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly.
}

/**
 * Class Enqueues
 *
 * Plugin term-meta class for Gigneo.
 *
 * @since 0.0.1
 */
class Enqueues {


	/**
	 * The single instance of the class.
	 *
	 * @var Enqueues|null
	 * @since 0.0.1
	 */
	private static $instance = null;

	/**
	 * Constructor for the class.
	 *
	 * @since 0.0.1
	 */
	public function __construct() {
		// Admin Enqueues
		add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue' ) );

		// Frontend Enqueues
		add_action( 'wp_enqueue_scripts', array( $this, 'frontend_enqueue' ) );

		//Elementor Editor Enqueues
		add_action( 'elementor/editor/before_enqueue_scripts', array( $this, 'elementor_editor_enqueue' ) );
	}

	/**
	 * Ensures only one instance of the class is loaded or can be loaded.
	 *
	 * @return Enqueues
	 * @since 0.0.1
	 */
	public static function instance() {
		if ( is_null( self::$instance ) ) {
			self::$instance = new self();
		}

		return self::$instance;
	}

	/**
	 * Enqueues admin scripts.
	 *
	 * @since 0.0.1
	 */
	public function admin_enqueue( $hook ) {

		global $post;

		$gn_pts = Post_Types::post_type_slug();
		$gn_tns = Taxonomies::taxonomy_slug();

		// Get the sanitized page parameter
		$page = filter_input( INPUT_GET, 'page', FILTER_SANITIZE_FULL_SPECIAL_CHARS );

		// Get the sanitized taxonomy parameter
		$taxonomy = filter_input( INPUT_GET, 'taxonomy', FILTER_SANITIZE_FULL_SPECIAL_CHARS );

		//Hero Icons - CSS
		wp_register_style(
			'hero-icons',
			GIGNEO_DIR_URL . 'assets/vendor/css/hero-icons.min.css',
			null,
			'2.1.5'
		);

		//Select2 - CSS
		wp_register_style(
			'select2',
			GIGNEO_DIR_URL . 'assets/vendor/css/select2.min.css',
			null,
			'4.1.0'
		);

		//Select2 - JS
		wp_register_script(
			'select2',
			GIGNEO_DIR_URL . 'assets/vendor/js/select2.min.js',
			array( 'jquery' ),
			'4.1.0',
			true
		);

		//Sweetalert - CSS
		wp_register_style(
			'sweetalert2',
			GIGNEO_DIR_URL . 'assets/vendor/css/sweetalert2.min.css',
			null,
			'11.26.24'
		);

		//Sweetalert - JS
		wp_register_script(
			'sweetalert2',
			GIGNEO_DIR_URL . 'assets/vendor/js/sweetalert2.min.js',
			null,
			'11.26.24',
			true
		);

		//Post Types
		if ( ! empty( $post->post_type ) && isset( $gn_pts[ $post->post_type ] ) ) {

			//Hero Icons
			wp_enqueue_style( 'hero-icons' );

			//Select2
			wp_enqueue_style( 'select2' );
			wp_enqueue_script( 'select2' );

			//SweetAlert2
			wp_enqueue_style( 'sweetalert2' );
			wp_enqueue_script( 'sweetalert2' );
		}

		//Taxonomies
		if ( ! empty( $taxonomy ) && isset( $gn_tns[ $taxonomy ] ) ) {

			//Hero Icons
			wp_enqueue_style( 'hero-icons' );

			//Select2
			wp_enqueue_style( 'select2' );
			wp_enqueue_script( 'select2' );

		}

		//Users
		if ( 'users.php' === $hook ) {
			//SweetAlert2
			wp_enqueue_style( 'sweetalert2' );
			wp_enqueue_script( 'sweetalert2' );
		}

		if ( 'gigneo' === $page || 'gigneo-modules' === $page || 'gigneo-license' === $page || 'gigneo-tools' === $page ) {

			//Hero Icons
			wp_enqueue_style( 'hero-icons' );

			//Select2
			wp_enqueue_style( 'select2' );
			wp_enqueue_script( 'select2' );

			//SweetAlert2
			wp_enqueue_style( 'sweetalert2' );
			wp_enqueue_script( 'sweetalert2' );

		}

		//Admin Backend - CSS
		wp_enqueue_style(
			'gigneo-admin-common',
			GIGNEO_DIR_URL . 'assets/admin/css/common.css',
			null,
			GIGNEO_VERSION
		);

		//Admin Backend - JS
		wp_enqueue_script(
			'gigneo-admin-common',
			GIGNEO_DIR_URL . 'assets/admin/js/common.js',
			array( 'jquery' ),
			GIGNEO_VERSION,
			array( 'in_footer' => true )
		);

		//Dashboards
		if ( 'gigneo' === $page || 'gigneo-modules' === $page || 'gigneo-license' === $page || 'gigneo-tools' === $page ) {

			//Hero Icons
			wp_enqueue_style( 'hero-icons' );

			//Admin Dashboard - CSS
			wp_enqueue_style(
				'gigneo-admin-dashboard',
				GIGNEO_DIR_URL . 'assets/admin/css/dashboard.css',
				null,
				GIGNEO_VERSION
			);

		}

		//Theme Options
		if ( 'gigneo-options' === $page ) {

			//Hero Icons
			wp_enqueue_style( 'hero-icons' );

			//Select2
			wp_enqueue_style( 'select2' );
			wp_enqueue_script( 'select2' );

			//Theme Options - CSS
			wp_enqueue_style(
				'gigneo-theme-option',
				GIGNEO_DIR_URL . 'assets/admin/css/theme-option.css',
				null,
				GIGNEO_VERSION
			);

		}

		//Post Meta
		if ( isset( $post ) && ( 'post-new.php' === $hook || 'post.php' === $hook ) ) {

			if ( ! empty( $post->post_type ) && isset( $gn_pts[ $post->post_type ] ) ) {

				//Hero Icons
				wp_enqueue_style( 'hero-icons' );

				//Select2
				wp_enqueue_style( 'select2' );
				wp_enqueue_script( 'select2' );

				//Post Meta - CSS
				wp_enqueue_style(
					'gigneo-post-meta',
					GIGNEO_DIR_URL . 'assets/admin/css/post-meta.css',
					null,
					GIGNEO_VERSION
				);

			}
		}

		//Admin Order
		if ( isset( $post ) && 'gigneo_order' === $post->post_type && in_array( $hook, array( 'post.php', 'edit.php' ), true ) ) {

			//Hero Icons
			wp_enqueue_style( 'hero-icons' );

			//Select2
			wp_enqueue_style( 'select2' );
			wp_enqueue_script( 'select2' );

			//Bootstrap - CSS
			wp_enqueue_style(
				'bootstrap',
				GIGNEO_DIR_URL . 'assets/vendor/css/bootstrap.min.css',
				null,
				'5.3.5'
			);

			//Order Admin - CSS
			wp_enqueue_style(
				'gigneo-admin-order',
				GIGNEO_DIR_URL . 'assets/admin/css/order.css',
				null,
				GIGNEO_VERSION
			);

			//Order Admin - JS
			wp_enqueue_script(
				'gigneo-admin-order',
				GIGNEO_DIR_URL . 'assets/admin/js/order.js',
				array( 'jquery' ),
				GIGNEO_VERSION,
				array( 'in_footer' => true )
			);

		}

		$gigneo_backend_localized_data = array(
			'email_verified_title'           => esc_html__( 'Email verified', 'gigneo' ),
			'email_verified_desc'            => esc_html__( 'This user email is verified.', 'gigneo' ),
			'email_unverified_title'         => esc_html__( 'Email unverified', 'gigneo' ),
			'email_unverified_desc'          => esc_html__( 'This user email is currently unverified.', 'gigneo' ),
			'service_status_title'           => esc_html__( 'Update service status', 'gigneo' ),
			'service_status_desc'            => esc_html__( 'Please click the button below to update the status of this service.', 'gigneo' ),
			'reject_title'                   => esc_html__( 'Reject service', 'gigneo' ),
			'reject_status_desc'             => esc_html__( 'Please provide a reason for rejection below.', 'gigneo' ),
			'reject_reason_placeholder'      => esc_html__( 'Rejection reason', 'gigneo' ),
			'reject_reason_required'         => esc_html__( 'Rejection reason is required', 'gigneo' ),
			'create_freelancer_profile_desc' => sprintf(
				// translators: %s is freelancer singular name.
				esc_html__( 'Are you sure you want to create a %s profile?', 'gigneo' ),
				gigneo_freelancer_singular()
			),
			'create_employer_profile_desc'   => sprintf(
				// translators: %s is employer singular name.
				esc_html__( 'Are you sure you want to create a %s profile?', 'gigneo' ),
				gigneo_employer_singular()
			),
			'confirmation_title'             => esc_html__( 'Are you sure?', 'gigneo' ),
			'confirmation_desc'              => esc_html__( 'Are you sure you want to do this? This action cannot be undone.', 'gigneo' ),
			'confirm_btn_text'               => esc_html__( 'Delete', 'gigneo' ),
			'cancel_btn_text'                => esc_html__( 'Delete', 'gigneo' ),
			'admin_chat_url'                 => esc_url( admin_url( 'admin.php?page=gigneo-tools&tab=chat_history' ) ),
			'facet_change'                   => esc_html__( 'You changed the categories. Please save and reload the page to update plan features fields.', 'gigneo' ),
			'price_format'                   => array(
				'currency_symbol'    => html_entity_decode( get_woocommerce_currency_symbol() ),
				'currency_position'  => get_option( 'woocommerce_currency_pos' ),
				'decimal_separator'  => wc_get_price_decimal_separator(),
				'thousand_separator' => wc_get_price_thousand_separator(),
				'price_decimals'     => wc_get_price_decimals(),
			),
		);

		if ( in_array( 'close_account', gigneo_active_modules(), true ) ) {
			$gigneo_backend_localized_data['account_closed']      = esc_html__( 'Account Closed', 'gigneo' );
			$gigneo_backend_localized_data['account_closed_desc'] = esc_html__( 'This account has been permanently closed and is no longer accessible.', 'gigneo' );
		}

		$gigneo_backend_localized_data = array_merge( $this->general_localized_data(), $gigneo_backend_localized_data );
		$gigneo_backend_localized_data = apply_filters( 'gigneo_backend_localized_data', $gigneo_backend_localized_data );
		wp_localize_script(
			'gigneo-admin-common',
			'GigneoBackendCommon',
			$gigneo_backend_localized_data
		);
	}

	/**
	 * Returns general localized data for scripts.
	 *
	 * @since 0.0.1
	 */
	public function general_localized_data() {

		$primary_color   = gigneo_option( '_gigneo_ts_primary_color', apply_filters( 'gigneo_primary_color', '#7E4CFF' ) );
		$secondary_color = gigneo_option( '_gigneo_ts_secondary_color', apply_filters( 'gigneo_secondary_color', '#EBEBEB' ) );

		$localized = array(
			'ajax_url'                           => admin_url( 'admin-ajax.php' ),
			'home_url'                           => home_url(),
			'security'                           => wp_create_nonce( 'gigneo_security' ),
			'session_expired_msg'                => esc_html__( 'Your session has expired. Please reload the page and try again.', 'gigneo' ),
			'timezone'                           => gigneo_timezone(),
			'primary_color'                      => $primary_color,
			'secondary_color'                    => $secondary_color,
			'service_creation_type'              => gigneo_option( '_gigneo_ts_service_creation_type', 'paid' ),
			'service_creation_credits'           => gigneo_option( '_gigneo_ts_service_creation_credits', '10' ),
			'service_update_credits_desc'        => esc_html__( 'You need to add or update your credits to continue posting services.', 'gigneo' ),
			'yes'                                => esc_html__( 'Yes', 'gigneo' ),
			'no'                                 => esc_html__( 'No', 'gigneo' ),
			'none'                               => esc_html__( 'None', 'gigneo' ),
			'confirm'                            => esc_html__( 'Confirm', 'gigneo' ),
			'cancel'                             => esc_html__( 'Cancel', 'gigneo' ),
			'delete'                             => esc_html__( 'Delete', 'gigneo' ),
			'error'                              => esc_html__( 'Error', 'gigneo' ),
			'success'                            => esc_html__( 'Success', 'gigneo' ),
			'warning'                            => esc_html__( 'Warning', 'gigneo' ),
			'remove'                             => esc_html__( 'Remove', 'gigneo' ),
			'draft'                              => esc_html__( 'Draft', 'gigneo' ),
			'close'                              => esc_html__( 'Close', 'gigneo' ),
			'verify'                             => esc_html__( 'Verify', 'gigneo' ),
			'unverify'                           => esc_html__( 'Unverify', 'gigneo' ),
			'complete'                           => esc_html__( 'Complete', 'gigneo' ),
			'approve'                            => esc_html__( 'Approve', 'gigneo' ),
			'reject'                             => esc_html__( 'Reject', 'gigneo' ),
			'decline'                            => esc_html__( 'Decline', 'gigneo' ),
			'create'                             => esc_html__( 'Create', 'gigneo' ),
			'reopen'                             => esc_html__( 'Reopen', 'gigneo' ),
			'block'                              => esc_html__( 'Block', 'gigneo' ),
			'unblock'                            => esc_html__( 'Unblock', 'gigneo' ),
			'disconnect'                         => esc_html__( 'Disconnect', 'gigneo' ),
			'went_wrong'                         => esc_html__( 'Something went wrong.', 'gigneo' ),
			'modal_title'                        => esc_html__( 'Choose a File', 'gigneo' ),
			'select_btn'                         => esc_html__( 'Select File', 'gigneo' ),
			'save_notice'                        => esc_html__( 'Don’t forget to save changes!', 'gigneo' ),
			'file_size_notice'                   => esc_html__( 'File is too large. Max file size is: ', 'gigneo' ),
			'invalid_extension_notice'           => esc_html__( 'Invalid file extension. Allowed extensions are: ', 'gigneo' ),
			'duplicate_document_notice'          => esc_html__( 'Duplicate document selected.', 'gigneo' ),
			'duplicate_image_notice'             => esc_html__( 'Duplicate image selected.', 'gigneo' ),
			'confirmation_title'                 => esc_html__( 'Are you sure?', 'gigneo' ),
			'confirmation_desc'                  => esc_html__( 'Are you sure you want to do this? This action cannot be undone.', 'gigneo' ),
			'cancel_confirmation_desc'           => esc_html__( 'Are you sure you want to cancel? This action cannot be undone.', 'gigneo' ),
			'disconnect_confirmation_desc'       => esc_html__( 'Are you sure you want to disconnect? This action cannot be undone.', 'gigneo' ),
			'delete_confirmation_desc'           => esc_html__( 'Are you sure you want to delete? This action cannot be undone.', 'gigneo' ),
			'complete_confirmation_desc'         => esc_html__( 'Are you sure you want to complete? This action cannot be undone.', 'gigneo' ),
			'pause_confirmation_desc'            => esc_html__( 'Are you sure you want to pause? You can activate at any time.', 'gigneo' ),
			'active_confirmation_desc'           => esc_html__( 'Are you sure you want to active? This action will make them visible to others.', 'gigneo' ),
			'draft_confirmation_desc'            => esc_html__( 'Are you sure you want to draft? You can activate at any time.', 'gigneo' ),
			'featured_confirmation_desc'         => esc_html__( 'Are you sure you want to featured? You can remove featured at any time.', 'gigneo' ),
			'removed_featured_confirmation_desc' => esc_html__( 'Are you sure you want to remove featured? You can featured at any time.', 'gigneo' ),
			'select2_placeholder'                => esc_html__( 'Select Option', 'gigneo' ),
			'select2_not_found'                  => esc_html__( 'No result found', 'gigneo' ),
			'select2_searching'                  => esc_html__( 'Searching...', 'gigneo' ),
			'select2_max_selection'              => esc_html__( 'You have reached the maximum limit.', 'gigneo' ),
			'required_fields'                    => esc_html__( 'Required fields could not be empty.', 'gigneo' ),
			'message_required_fields'            => esc_html__( 'Message or attachments could not be empty.', 'gigneo' ),
			'result_count_text'                  => esc_html__( '{{count}} Results found', 'gigneo' ),
			'job_order_place_confirmation_title' => esc_html__( 'Confirmation!', 'gigneo' ),
			'job_order_place_confirmation_desc'  => esc_html__( 'Are you sure you want to hire.', 'gigneo' ),
			'job_order_place_confirmation_btn'   => esc_html__( 'Confirm & hire', 'gigneo' ),
			'login_required_msg'                 => esc_html__( 'You need to log in to use the save option.', 'gigneo' ),
			'auth_popup'                         => gigneo_option( '_gigneo_ts_auth_popup' ),
			'login_url'                          => ! empty( gigneo_option( '_gigneo_ts_template_login' ) ) ? get_permalink( gigneo_option( '_gigneo_ts_template_login' ) ) : home_url(),
		);

		return apply_filters( 'gigneo_general_localized_data', $localized );
	}

	/**
	 * Enqueues frontend scripts and styles.
	 *
	 * This function enqueues the necessary scripts and styles for the frontend.
	 *
	 *
	 * @since 0.0.1
	 */
	public function frontend_enqueue() {

		//Gigneo Icons - CSS
		wp_enqueue_style(
			'hero-icons',
			GIGNEO_DIR_URL . 'assets/vendor/css/hero-icons.min.css',
			null,
			'2.1.5'
		);

		//Select2 - CSS
		wp_enqueue_style(
			'select2',
			GIGNEO_DIR_URL . 'assets/vendor/css/select2.min.css',
			null,
			'4.1.0'
		);

		//Select2 - JS
		wp_enqueue_script(
			'select2',
			GIGNEO_DIR_URL . 'assets/vendor/js/select2.min.js',
			array( 'jquery' ),
			'4.1.0',
			array( 'in_footer' => true )
		);

		//Isotope - JS
		wp_register_script(
			'isotope',
			GIGNEO_DIR_URL . 'assets/vendor/js/isotope.pkgd.min.js',
			array( 'jquery' ),
			'3.0.6',
			array( 'in_footer' => true )
		);

		//Select2 - CSS
		wp_enqueue_style(
			'nouislider',
			GIGNEO_DIR_URL . 'assets/vendor/css/nouislider.min.css',
			null,
			'15.8.1'
		);

		//Select2 - JS
		wp_enqueue_script(
			'nouislider',
			GIGNEO_DIR_URL . 'assets/vendor/js/nouislider.min.js',
			array( 'jquery' ),
			'15.8.1',
			array( 'in_footer' => true )
		);

		//Fancybox - CSS
		wp_enqueue_style(
			'fancybox',
			GIGNEO_DIR_URL . 'assets/vendor/css/fancybox.min.css',
			null,
			'3.5.7'
		);

		//Fancybox - JS
		wp_enqueue_script(
			'fancybox',
			GIGNEO_DIR_URL . 'assets/vendor/js/fancybox.min.js',
			array( 'jquery' ),
			'3.5.7',
			array( 'in_footer' => true )
		);

		//Uploader
		wp_enqueue_script(
			'gigneo-uploader',
			GIGNEO_DIR_URL . 'assets/vendor/js/uploader.min.js',
			array( 'jquery', 'media-views', 'media-editor' ),
			'1.0.0',
			array( 'in_footer' => true )
		);

		// HeaderTool Shim for frontend cropping
		wp_add_inline_script(
			'gigneo-uploader',
			"window.wp = window.wp || {};
			wp.customize = wp.customize || {};
			wp.customize.HeaderTool = wp.customize.HeaderTool || {};
			if ( ! wp.customize.HeaderTool.ImageModel ) {
				wp.customize.HeaderTool.ImageModel = Backbone.Model.extend({
					shouldBeCropped: function() {
						return ( this.get('imageWidth') > this.get('themeWidth') || this.get('imageHeight') > this.get('themeHeight') );
					}
				});
			}",
			'before'
		);

		//Sweetalert - CSS
		wp_enqueue_style(
			'sweetalert2',
			GIGNEO_DIR_URL . 'assets/vendor/css/sweetalert2.min.css',
			null,
			'11.26.24'
		);

		//Sweetalert - JS
		wp_enqueue_script(
			'sweetalert2',
			GIGNEO_DIR_URL . 'assets/vendor/js/sweetalert2.min.js',
			array( 'jquery' ),
			'11.26.24',
			array( 'in_footer' => true )
		);

		//Flatpickr- CSS
		wp_enqueue_style(
			'flatpickr',
			GIGNEO_DIR_URL . 'assets/vendor/css/flatpickr.min.css',
			null,
			'4.6.13',
		);

		//Flatpickr - JS
		wp_enqueue_script(
			'flatpickr',
			GIGNEO_DIR_URL . 'assets/vendor/js/flatpickr.min.js',
			array( 'jquery' ),
			'1.8.1',
			array( 'in_footer' => true )
		);

		//Slick - CSS
		wp_enqueue_style(
			'slick',
			GIGNEO_DIR_URL . 'assets/vendor/css/slick.min.css',
			null,
			'1.8.1'
		);

		//Slick - JS
		wp_enqueue_script(
			'slick',
			GIGNEO_DIR_URL . 'assets/vendor/js/slick.min.js',
			array( 'jquery' ),
			'11.26.24',
			array( 'in_footer' => true )
		);

		//Common - CSS
		wp_enqueue_style(
			'gigneo-common',
			GIGNEO_DIR_URL . 'assets/css/common.css',
			null,
			GIGNEO_VERSION
		);

		//Common RTL - CSS
		if ( is_rtl() ) {
			wp_enqueue_style(
				'gigneo-common-rtl',
				GIGNEO_DIR_URL . 'assets/css/common-rtl.css',
				array( 'gigneo-common' ),
				GIGNEO_VERSION
			);
		}

		//Common - JS
		wp_enqueue_script(
			'gigneo-common',
			GIGNEO_DIR_URL . 'assets/js/common.js',
			array( 'jquery', 'heartbeat' ),
			GIGNEO_VERSION,
			array( 'in_footer' => true )
		);

		//Localize common data
		$general_common_localize_data = $this->general_localized_data();

		$gigneo_common_localized_data = array(
			'user_id'                   => get_current_user_id(),
			'profile_id'                => gigneo_active_profile_id(),
			'flatpickr_date_format'     => gigneo_flatpickr_date_format( get_option( 'date_format' ) ),
			'placeholder_url'           => gigneo_placeholder_url(),
			'doc_placeholder_url'       => GIGNEO_DIR_URL . 'assets/img/icon/document.png',
			'password_strength'         => gigneo_option( '_gigneo_ts_password_strength', array( 'length' ) ),
			'price_format'              => array(
				'currency_symbol'    => html_entity_decode( get_woocommerce_currency_symbol() ),
				'currency_position'  => get_option( 'woocommerce_currency_pos' ),
				'decimal_separator'  => wc_get_price_decimal_separator(),
				'thousand_separator' => wc_get_price_thousand_separator(),
				'price_decimals'     => wc_get_price_decimals(),
			),
			'active_modules'            => Modules::active_modules(),
			'notification_type'         => gigneo_option( '_gigneo_ts_notification_type', 'heartbeat' ),
			'notification_onscreen'     => gigneo_option( '_gigneo_ts_notification_onscreen', true ),
			'heartbeat_interval'        => gigneo_option( '_gigneo_ts_heartbeat_interval', 60 ),
			'order_messages_limit'      => gigneo_option( '_gigneo_ts_messages_limit', '30' ),
			'job_document_extensions'   => gigneo_option( '_gigneo_ts_job_attachment_extensions', array( 'jpg', 'jpeg', 'png', 'pdf', 'doc', 'docx', 'mp4' ) ),
			'job_document_max_size'     => (int) gigneo_option( '_gigneo_ts_job_attachment_max_size', 5 ),
			'job_document_limit'        => (int) gigneo_option( '_gigneo_ts_job_attachment_limit', 1 ),
			'job_order_extensions'      => gigneo_option( '_gigneo_ts_job_order_extensions', array( 'jpg', 'jpeg', 'png', 'pdf', 'doc', 'docx', 'mp4' ) ),
			'job_order_max_size'        => (int) gigneo_option( '_gigneo_ts_job_order_max_size', 5 ),
			'job_order_limit'           => (int) gigneo_option( '_gigneo_ts_job_order_max_files', 5 ),
			'proposal_employer_message' => sprintf(
				// translators: %s is freelancer plural name.
				esc_html__( 'Only %s can send proposal', 'gigneo' ),
				gigneo_freelancer_plural()
			),
			'proposal_author_message'   => esc_html__( 'You can not send proposal own job posting', 'gigneo' ),
			'proposal_login_message'    => esc_html__( 'You need to log in to send proposal.', 'gigneo' ),
			'proposal_sent_message'     => esc_html__( 'You have already sent a proposal for this job.', 'gigneo' ),

		);

		if ( in_array( 'intake_form', gigneo_active_modules(), true ) ) {

			// Enqueue PLUpload
			wp_enqueue_script( 'plupload-all' );
		}

		$gigneo_common_localized_data = apply_filters( 'gigneo_common_localized_data', $gigneo_common_localized_data );

		wp_localize_script(
			'gigneo-common',
			'GigneoCommon',
			array_merge( $gigneo_common_localized_data, $general_common_localize_data )
		);

		// Custom font & Inline CSS (font families only when Google Fonts opt-in is enabled).
		$primary_font   = gigneo_option( '_gigneo_ts_primary_font', apply_filters( 'gigneo_primary_font', '' ) );
		$secondary_font = gigneo_option( '_gigneo_ts_secondary_font', apply_filters( 'gigneo_secondary_font', '' ) );

		$primary_color   = gigneo_option( '_gigneo_ts_primary_color', apply_filters( 'gigneo_primary_color', '' ) );
		$secondary_color = gigneo_option( '_gigneo_ts_secondary_color', apply_filters( 'gigneo_secondary_color', '' ) );

		$custom_css = ':root {';
		if ( ! empty( $primary_font ) ) {
			$custom_css .= "--gigneo-primary-font: '" . esc_attr( $primary_font ) . "', sans-serif;";
		}
		if ( ! empty( $primary_color ) ) {
			$primary_color = gigneo_hex_to_rgb( $primary_color, false, 0 );
			$custom_css   .= "--gigneo-primary-color: $primary_color;";
		}
		if ( ! empty( $secondary_font ) ) {
			$custom_css .= "--gigneo-secondary-font: '" . esc_attr( $secondary_font ) . "', sans-serif;";
		}
		if ( ! empty( $secondary_color ) ) {
			$secondary_color = gigneo_hex_to_rgb( $secondary_color, false, 0 );
			$custom_css     .= "--gigneo-secondary-color: $secondary_color;";
		}
		$custom_css .= '}';

		wp_add_inline_style( 'gigneo-common', wp_kses( $custom_css, array() ) );

		//Dashboard Template
		$dashboard_template = gigneo_option( '_gigneo_ts_template_dashboard' );

		// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only parameters no nonce required.
		$source = ! empty( $_GET['source'] ) ? sanitize_text_field( wp_unslash( $_GET['source'] ) ) : '';
		// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only parameters no nonce required.
		$ref = ! empty( $_GET['ref'] ) ? sanitize_text_field( wp_unslash( $_GET['ref'] ) ) : '';

		if ( empty( $dashboard_template ) || ! is_page( $dashboard_template ) ) {
			//Frontend - CSS
			wp_enqueue_style(
				'gigneo-frontend',
				GIGNEO_DIR_URL . 'assets/css/frontend.css',
				null,
				GIGNEO_VERSION
			);

			//Frontend RTL - CSS
			if ( is_rtl() ) {
				wp_enqueue_style(
					'gigneo-frontend-rtl',
					GIGNEO_DIR_URL . 'assets/css/frontend-rtl.css',
					array( 'gigneo-frontend' ),
					GIGNEO_VERSION
				);
			}

			//Frontend - JS
			wp_enqueue_script(
				'gigneo-frontend',
				GIGNEO_DIR_URL . 'assets/js/frontend.js',
				array( 'gigneo-common' ),
				GIGNEO_VERSION,
				array( 'in_footer' => true )
			);

			do_action( 'gigneo_frontend_enqueues' );

		}

		//Dashboard Enqueue
		$this->dashboard_enqueue();
	}

	/**
	 * Enqueues dashboard scripts and styles for the Gigneo plugin.
	 *
	 * Handles loading of all necessary assets and localized data for the dashboard template.
	 *
	 * @since 0.0.1
	 */
	public function dashboard_enqueue() {

		//Dashboard Template
		$dashboard_template = gigneo_option( '_gigneo_ts_template_dashboard' );

		if ( empty( $dashboard_template ) || ! is_page( $dashboard_template ) ) {
			return false;
		}

		// phpcs:disable WordPress.Security.NonceVerification.Recommended -- Read-only parameters no nonce required.
		$source = ! empty( $_GET['source'] ) ? sanitize_text_field( wp_unslash( $_GET['source'] ) ) : '';
		$ref    = ! empty( $_GET['ref'] ) ? sanitize_text_field( wp_unslash( $_GET['ref'] ) ) : '';
		// phpcs:enable WordPress.Security.NonceVerification.Recommended -- Read-only parameters no nonce required.

		// Custom fonts from Google — only when admin opted in (Appearance → Load Google Fonts).
		$load_google_fonts = gigneo_option( '_gigneo_ts_load_google_fonts', false );
		$primary_font      = gigneo_option( '_gigneo_ts_primary_font' );
		$secondary_font    = gigneo_option( '_gigneo_ts_secondary_font' );

		if ( $load_google_fonts ) {
			// Primary Google Font
			if ( ! empty( $primary_font ) ) {
				$primary_font_slug = strtolower( str_replace( ' ', '-', $primary_font ) );
				$primary_font_name = rawurlencode( $primary_font );
				wp_enqueue_style( "google-$primary_font_slug", 'https://fonts.googleapis.com/css2?family=' . $primary_font_name . ':ital,wght@0,300..900;1,300..900&display=swap', array(), GIGNEO_VERSION );
			}

			// Secondary Google Font
			if ( ! empty( $secondary_font ) ) {
				$secondary_font_slug = strtolower( str_replace( ' ', '-', $secondary_font ) );
				$secondary_font_name = rawurlencode( $secondary_font );
				wp_enqueue_style( "google-$secondary_font_slug", 'https://fonts.googleapis.com/css2?family=' . $secondary_font_name . ':ital,wght@0,300..900;1,300..900&display=swap', array(), GIGNEO_VERSION );
			}
		}

		// Enqueue Media
		wp_enqueue_media();
		wp_enqueue_script( 'imgareaselect' );
		wp_enqueue_style( 'imgareaselect' );

		//Chart.js
		wp_register_script(
			'chartjs',
			GIGNEO_DIR_URL . 'assets/vendor/js/chart.min.js',
			array( 'gigneo-dashboard' ),
			'4.5.1',
			true
		);

		//Bootstrap - CSS
		wp_enqueue_style(
			'bootstrap',
			GIGNEO_DIR_URL . 'assets/vendor/css/bootstrap.min.css',
			null,
			'5.3.5'
		);

		//Dashboard - CSS
		wp_enqueue_style(
			'gigneo-dashboard',
			GIGNEO_DIR_URL . 'assets/dashboard/css/general.css',
			array( 'gigneo-common' ),
			GIGNEO_VERSION
		);

		//Dashboard - JS
		wp_enqueue_script(
			'gigneo-dashboard',
			GIGNEO_DIR_URL . 'assets/dashboard/js/general.js',
			array( 'jquery', 'heartbeat', 'select2' ),
			GIGNEO_VERSION,
			array( 'in_footer' => true )
		);

		$custom_css = '';

		//Dashboard Color
		$dashboard_scheme = gigneo_option( '_gigneo_ts_dashboard_menu_scheme', 'default' );
		$dashboard_color  = gigneo_option( '_gigneo_ts_dashboard_layout_background' );
		$service_prefix   = gigneo_option( '_gigneo_ts_service_title_prefix' );

		if ( 'default' !== $dashboard_scheme && ! empty( $dashboard_color ) ) {
			$dashboard_color = gigneo_hex_to_rgb( $dashboard_color, false );
			$custom_css     .= ".gn-dashboard-wrapper { --gigneo-layout-background: $dashboard_color; }";
		}

		if ( ! empty( $service_prefix ) ) {
			$custom_css .= '.gn-edit-service-textarea textarea { text-indent: ' . esc_html( strlen( $service_prefix ) * 6.6 ) . 'px; }';
		}

		$custom_css .= ".gn-dashboard-wrapper { --gigneo-text-show: '" . esc_html__( 'Show:', 'gigneo' ) . "'; }";

		wp_add_inline_style( 'gigneo-dashboard', wp_kses( $custom_css, array() ) );

		//Account
		if ( empty( $source ) || 'account' === $source ) {

			wp_enqueue_style(
				'gigneo-dashboard-account',
				GIGNEO_DIR_URL . 'assets/dashboard/css/account.css',
				array( 'gigneo-dashboard' ),
				GIGNEO_VERSION
			);

			wp_enqueue_script(
				'gigneo-dashboard-account',
				GIGNEO_DIR_URL . 'assets/dashboard/js/account.js',
				array( 'chartjs', 'gigneo-dashboard' ),
				GIGNEO_VERSION,
				true
			);

		}

		//Setting
		if ( 'setting' === $source ) {

			wp_enqueue_style(
				'gigneo-dashboard-setting',
				GIGNEO_DIR_URL . 'assets/dashboard/css/setting.css',
				array( 'gigneo-dashboard' ),
				GIGNEO_VERSION
			);

			wp_enqueue_script(
				'gigneo-dashboard-setting',
				GIGNEO_DIR_URL . 'assets/dashboard/js/setting.js',
				array( 'chartjs', 'gigneo-dashboard' ),
				GIGNEO_VERSION,
				array( 'in_footer' => true )
			);

		}

		$post_type_slugs = Post_Types::post_type_slug();

		//Service
		if ( $post_type_slugs['gigneo_service'] === $source ) {

			wp_enqueue_style(
				'gigneo-dashboard-service',
				GIGNEO_DIR_URL . 'assets/dashboard/css/service.css',
				array( 'gigneo-dashboard' ),
				GIGNEO_VERSION
			);

			wp_enqueue_script(
				'gigneo-dashboard-service',
				GIGNEO_DIR_URL . 'assets/dashboard/js/service.js',
				array( 'underscore', 'wp-util', 'gigneo-dashboard' ),
				GIGNEO_VERSION,
				array( 'in_footer' => true )
			);

		}

		//Job
		if ( $post_type_slugs['gigneo_job'] === $source || 'proposal' === $source ) {

			wp_enqueue_style(
				'gigneo-dashboard-job',
				GIGNEO_DIR_URL . 'assets/dashboard/css/job.css',
				array( 'gigneo-dashboard' ),
				GIGNEO_VERSION
			);

			wp_enqueue_script(
				'gigneo-dashboard-job',
				GIGNEO_DIR_URL . 'assets/dashboard/js/job.js',
				array( 'underscore', 'wp-util', 'gigneo-dashboard' ),
				GIGNEO_VERSION,
				array( 'in_footer' => true )
			);

		}

		//Localization
		$dashboard_localized_data = array(
			'image_extensions'    => gigneo_option( '_gigneo_ts_image_extensions', array( 'jpg', 'jpeg', 'png', 'gif' ) ),
			'image_max_size'      => gigneo_option( '_gigneo_ts_image_max_size', '1' ),
			'video_extensions'    => gigneo_option( '_gigneo_ts_video_extensions', array( 'mp4', 'avi', 'mov' ) ),
			'video_max_size'      => gigneo_option( '_gigneo_ts_video_max_size', '10' ),
			'document_extensions' => gigneo_option( '_gigneo_ts_document_extensions', array( 'pdf', 'doc', 'ppt' ) ),
			'document_max_size'   => gigneo_option( '_gigneo_ts_document_max_size', '5' ),
			'cities'              => gigneo_country_state_cities( false, false ),
		);

		if ( $post_type_slugs['gigneo_service'] === $source ) {
			$dashboard_localized_data['max_service_custom_features']      = 5;
			$dashboard_localized_data['custom_features']                  = esc_html__( 'Custom feature', 'gigneo' );
			$dashboard_localized_data['empty_features_description']       = esc_html__( 'Please fill in the custom feature title', 'gigneo' );
			$dashboard_localized_data['max_custom_features_confirmation'] = sprintf(
				// translators: %s is max allowed custom features.
				esc_html__( 'You are not allowed to add more then %s custom features', 'gigneo' ),
				$dashboard_localized_data['max_service_custom_features']
			);
			$dashboard_localized_data['default_sub_categories']            = esc_html__( 'Narrow down category', 'gigneo' );
			$dashboard_localized_data['country_states']                    = gigneo_countries_with_states( 'active' );
			$dashboard_localized_data['service_max_locations']             = gigneo_option( '_gigneo_ts_service_max_locations', '3' );
			$dashboard_localized_data['max_service_location']              = esc_html__( 'Location', 'gigneo' );
			$dashboard_localized_data['max_service_location_confirmation'] = sprintf(
				// translators: %s is max allowed locations.
				esc_html__( 'You are not allowed to add more then %s locations', 'gigneo' ),
				$dashboard_localized_data['service_max_locations']
			);
		}

		if ( $post_type_slugs['gigneo_job'] === $source ) {
			$dashboard_localized_data['job_document_extensions'] = gigneo_option( '_gigneo_ts_job_attachment_extensions', array( 'jpg', 'jpeg', 'png', 'pdf', 'doc', 'docx', 'mp4' ) );
			$dashboard_localized_data['job_document_max_size']   = (int) gigneo_option( '_gigneo_ts_job_attachment_max_size', 5 );
		}
		if ( $post_type_slugs['gigneo_service'] === $source || $post_type_slugs['gigneo_job'] === $source ) {
			$category_list  = gigneo_term_list(
				array(
					'taxonomy' => 'gigneo_facet',
					'parent'   => 0,
				),
				false
			);
			$sub_categories = array();
			foreach ( $category_list as $cat => $category ) {
				$cat_term = get_term_by( 'slug', $cat, 'gigneo_facet' );
				if ( $cat_term && ! is_wp_error( $cat_term ) ) {
					$sub_category_list      = gigneo_term_list(
						array(
							'taxonomy' => 'gigneo_facet',
							'parent'   => $cat_term->term_id,
						),
						false
					);
					$sub_categories[ $cat ] = $sub_category_list;
					foreach ( $sub_category_list as $sub_cat => $sub_category ) {
						$sub_cat_term = get_term_by( 'slug', $sub_cat, 'gigneo_facet' );
						if ( $sub_cat_term && ! is_wp_error( $sub_cat_term ) ) {
							$sub_categories[ $sub_cat ] = gigneo_term_list(
								array(
									'taxonomy' => 'gigneo_facet',
									'parent'   => $sub_cat_term->term_id,
								),
								false
							);
						}
					}
				}
			}
			$profile_id                                 = gigneo_active_profile_id();
			$total_credits                              = gigneo_available_credits( $profile_id );
			$dashboard_localized_data['total_credits']  = $total_credits;
			$dashboard_localized_data['sub_categories'] = $sub_categories;
		}

		if ( 'order' === $source ) {

			wp_enqueue_style(
				'gigneo-dashboard-order',
				GIGNEO_DIR_URL . 'assets/dashboard/css/order.css',
				array( 'gigneo-dashboard' ),
				GIGNEO_VERSION
			);

			wp_enqueue_script(
				'gigneo-dashboard-order',
				GIGNEO_DIR_URL . 'assets/dashboard/js/order.js',
				array( 'gigneo-dashboard' ),
				GIGNEO_VERSION,
				array( 'in_footer' => true )
			);

			$service_order_attachments = gigneo_option( '_gigneo_ts_service_order_extensions', array( 'jpg', 'jpeg', 'png', 'doc' ) );

			$dashboard_localized_data['decline_cancel_request_confirmation_desc']      = esc_html__( 'Are you sure you want to decline the cancel order request? This will keep your order active.', 'gigneo' );
			$dashboard_localized_data['approve_cancel_request_confirmation_desc']      = esc_html__( 'Are you sure you want to approve the cancel order request? This will mark your order as cancelled.', 'gigneo' );
			$dashboard_localized_data['decline_extend_date_request_confirmation_desc'] = esc_html__( 'Are you sure you want to decline the extend delivery date request? This action cannot be undone.', 'gigneo' );
			$dashboard_localized_data['approve_extend_date_request_confirmation_desc'] = esc_html__( 'Are you sure you want to approve the extend delivery date request? This action cannot be undone.', 'gigneo' );
			$dashboard_localized_data['approve_delivery_confirmation_desc']            = esc_html__( 'Are you sure you want to approve this delivery? This will mark your order as complete.', 'gigneo' );
			$dashboard_localized_data['service_order_extensions']                      = $service_order_attachments;
			$dashboard_localized_data['service_order_max_files']                       = gigneo_option( '_gigneo_ts_service_order_max_files', '3' );
			$dashboard_localized_data['service_order_max_size']                        = gigneo_option( '_gigneo_ts_service_order_max_size', '1' );
			$dashboard_localized_data['service_order_extension_notice']                = sprintf(
				// translators: %s is allowed extensions.
				esc_html__( 'Allowed extensions are: %s', 'gigneo' ),
				implode( ', ', $service_order_attachments )
			);
			$dashboard_localized_data['service_order_max_files_notice'] = sprintf(
				// translators: %s is upload limit.
				esc_html__( 'You can upload up to %s files.', 'gigneo' ),
				gigneo_option( '_gigneo_ts_service_order_max_files', '3' )
			);
			$dashboard_localized_data['service_order_max_size_notice'] = sprintf(
				// translators: %s maximum file size.
				esc_html__( 'Maximum file size is: %s MB', 'gigneo' ),
				gigneo_option( '_gigneo_ts_service_order_max_size', '1' )
			);

			$job_order_attachments                                  = gigneo_option( '_gigneo_ts_job_order_extensions', array( 'jpg', 'jpeg', 'png', 'doc' ) );
			$job_order_attachments                                  = is_array( $job_order_attachments ) ? $job_order_attachments : array( 'jpg', 'jpeg', 'png', 'doc' );
			$dashboard_localized_data['job_order_extensions']       = $job_order_attachments;
			$dashboard_localized_data['job_order_max_files']        = gigneo_option( '_gigneo_ts_job_order_max_files', '3' );
			$dashboard_localized_data['job_order_max_size']         = gigneo_option( '_gigneo_ts_job_order_max_size', '1' );
			$dashboard_localized_data['job_order_extension_notice'] = sprintf(
				// translators: %s is allowed extensions.
				esc_html__( 'Allowed extensions are: %s', 'gigneo' ),
				implode( ', ', $job_order_attachments )
			);
			$dashboard_localized_data['job_order_max_files_notice'] = sprintf(
				// translators: %s is upload limit.
				esc_html__( 'You can upload up to %s files.', 'gigneo' ),
				gigneo_option( '_gigneo_ts_job_order_max_files', '3' )
			);
			$dashboard_localized_data['job_order_max_size_notice'] = sprintf(
				// translators: %s maximum file size.
				esc_html__( 'Maximum file size is: %s MB', 'gigneo' ),
				gigneo_option( '_gigneo_ts_job_order_max_size', '1' )
			);
		} elseif ( 'notification' === $source ) {

			wp_enqueue_style(
				'gigneo-dashboard-notification',
				GIGNEO_DIR_URL . 'assets/dashboard/css/notification.css',
				array( 'gigneo-dashboard' ),
				GIGNEO_VERSION
			);

			wp_enqueue_script(
				'gigneo-dashboard-notification',
				GIGNEO_DIR_URL . 'assets/dashboard/js/notification.js',
				array( 'gigneo-dashboard' ),
				GIGNEO_VERSION,
				array( 'in_footer' => true )
			);
		}

		$dashboard_localized_data = apply_filters( 'gigneo_dashboard_localized_data', $dashboard_localized_data );

		wp_localize_script(
			'gigneo-dashboard',
			'GigneoDashboard',
			$dashboard_localized_data
		);

		do_action( 'gigneo_dashboard_enqueues' );

		//Dashboard RTL CSS
		if ( is_rtl() ) {
			wp_enqueue_style(
				'gigneo-dashboard-rtl',
				GIGNEO_DIR_URL . 'assets/dashboard/css/rtl.css',
				array( 'gigneo-dashboard' ),
				GIGNEO_VERSION
			);
		}
	}

	/**
	 * Enqueues Elementor editor scripts and styles.
	 *
	 * @since 0.0.1
	 */
	public function elementor_editor_enqueue() {

		//Editor - CSS
		wp_enqueue_style(
			'gigneo-ele-editor',
			GIGNEO_DIR_URL . 'assets/admin/css/ele-editor.css',
			null,
			GIGNEO_VERSION
		);

		//Editor - JS
		wp_enqueue_script(
			'gigneo-ele-editor',
			GIGNEO_DIR_URL . 'assets/admin/js/ele-editor.js',
			array( 'jquery' ),
			GIGNEO_VERSION,
			array( 'in_footer' => true )
		);
	}
}
