jQuery( document ).ready(function() {

	jQuery('#elex-multi-vendor-for-woocommerce-onboard-list > li > button[data-bs-toggle="pill"]').on('shown.bs.tab', function(e) {
		//update progress
		var step =  jQuery(e.target).data('step');
		var percent = (parseInt(step) / 9) * 100;
		jQuery('.elex-multi-vendor-for-woocommerce-onboard-inactive-progress-bar').css({width: (100 - percent) + '%'})

		jQuery('.elex-multi-vendor-for-woocommerce-onboard-active-progress-bar').css({ width: percent + '%' });
		//e.relatedTarget // previous tab

		if(step != 0){
			jQuery(".elex-multi-vendor-for-woocommerce-onboard-back-btn").show();
		}else{
			jQuery(".elex-multi-vendor-for-woocommerce-onboard-back-btn").hide();
		}



	})

	let page_num =  localStorage.getItem("setup-admin-page") || 0 ;
		page_num++;

	for(let i=0; i<page_num; i++){
	jQuery("#elex-multi-vendor-for-woocommerce-onboard-list button").eq(i).prop('disabled',false).addClass('elex-multi-vendor-for-woocommerce-on');

	}
   
	jQuery("#elex-multi-vendor-for-woocommerce-onboard-list button").eq(--page_num).click();


});

jQuery(".elex-multi-vendor-for-woocommerce-confirm-admin-setup-btn").click(function(){

	var formData;	
	var link = elexMvSetupUiParams.ajax_url;
	link += "?action=elex-multi-vendor-for-woocommerce-admin-intallation-setup" ;
	localStorage.setItem("setup-admin-page", jQuery(this).data("id") );

	var formData = new FormData(document.getElementById('elex-multi-vendor-for-woocommerce-admin-intallation-setup'));
	jQuery.ajax({
			url: link ,
			type: 'POST',
			data: formData,
			enctype: 'multipart/form-data',
			processData: false,
			contentType: false,
			success: function(result) {
				if(result.success){
					jQuery('#elex-multi-vendor-for-woocommerce-onboard-list.nav > li > .nav-link.active').parent().next('li').find('button').trigger('click');
					jQuery('#elex-multi-vendor-for-woocommerce-onboard-list.nav > li > .nav-link.active').addClass("elex-multi-vendor-for-woocommerce-on");
					var additem = document.getElementById('wsdesk_add_admin_settings_toast')
					var toast = new bootstrap.Toast(additem)
					toast.show();
				}else{
					event.preventDefault();
				}
				
			}
			
	})                     
})

jQuery(".elex-multi-vendor-for-woocommerce-skip-btn").click(function(){
	localStorage.setItem("setup-admin-page", jQuery(this).data("id") );
})


	jQuery(".elex-multi-vendor-for-woocommerce-confirm-admin-setup-finish-btn").click(function(){

	var formData;	
	var link = elexMvSetupUiParams.ajax_url;
	link += "?action=elex-multi-vendor-for-woocommerce-admin-intallation-setup" ;
	localStorage.setItem("setup-admin-page", 4 );
	var formData = new FormData(document.getElementById('elex-multi-vendor-for-woocommerce-admin-intallation-setup'));
	formData.append('is_setup_finished',true);
	jQuery.ajax({
			url: link ,
			type: 'POST',
			data: formData,
			enctype: 'multipart/form-data',
			processData: false,
			contentType: false,
			success: function(result) {
				localStorage.removeItem('setup-admin-page');
				location.pathname
				location.replace(location.pathname + "?page=elex-multi-vendor-for-woocommerce-settings");
			}
		
		})

	})


	jQuery(".elex-multi-vendor-for-woocommerce-onboard-back-btn").hide();
	   
	// jQuery('.elex-multi-vendor-for-woocommerce-confirm-admin-setup-btn').click(function() {
	// 	jQuery('#elex-multi-vendor-for-woocommerce-onboard-list.nav > li > .nav-link.active').parent().next('li').find('button').trigger('click');
	// 	jQuery('#elex-multi-vendor-for-woocommerce-onboard-list.nav > li > .nav-link.active').addClass("elex-multi-vendor-for-woocommerce-on");
	// });

	jQuery('.elex-multi-vendor-for-woocommerce-skip-btn').click(function() {
		jQuery('#elex-multi-vendor-for-woocommerce-onboard-list.nav > li > .nav-link.active').parent().next('li').find('button').trigger('click');
		jQuery('#elex-multi-vendor-for-woocommerce-onboard-list.nav > li > .nav-link.active').addClass("elex-multi-vendor-for-woocommerce-on");
	});
	jQuery('.elex-multi-vendor-for-woocommerce-onboard-back-btn').click(function() {
		jQuery('#elex-multi-vendor-for-woocommerce-onboard-list.nav > li > .nav-link.active ').parent().prev('li').find('button').trigger('click');
		jQuery('#elex-multi-vendor-for-woocommerce-onboard-list.nav > li > .nav-link.active').parent().next('li').find('button').removeClass("elex-multi-vendor-for-woocommerce-on");
	});
	jQuery(document).ready(function(){
		jQuery("#elex-multi-vendor-for-woocommerce-onboard-list button").click(function(){
			jQuery(this).tab('show');
		});
	});

	validation_for_forms_func('#elex_mv_admin_as_vendor_name',/^([ \u00c0-\u01ffa-zA-Z0-9'\-])+$/, '#elex_mv_admin_as_vendor_name_error', 'Enter Valid Name ')

validation_for_forms_func('#elex_mv_admin_as_vendor_city', /^([ \u00c0-\u01ffa-zA-Z'\-])+$/, '#elex_mv_admin_as_vendor_city_error', 'Enter valid city')
validation_for_forms_func('#elex_mv_admin_as_vendor_postal_code', /(^[a-z0-9][a-z0-9\- ]){0,10}[a-z0-9]$/, '#elex_mv_admin_as_vendor_postal_code_error', 'Enter valid postal num in integers')
validation_for_forms_func('#elex_mv_admin_as_vendor_state', /^([ \u00c0-\u01ffa-zA-Z'\-])+$/, '#elex_mv_admin_as_vendor_state_error', 'Enter valid state in alphabets')
validation_for_forms_func('#elex_mv_admin_as_vendor_country', /^([ \u00c0-\u01ffa-zA-Z'\-])+$/, '#elex_mv_admin_as_vendor_country_error', 'Enter valid country')
validation_for_forms_func('#elex_mv_admin_as_vendor_phone_number', /^[0-9]*$/, '#elex_mv_admin_as_vendor_phone_number_error', 'Enter valid number')
