jQuery( document ).ready(
	function ($) {
		$( document ).on(
			'click',
			'.wawp-send-otp-front',
			function (e) {
				e.preventDefault();
				var uid = $( this ).data( 'userid' );
				$.ajax(
					{
						url: wawpFrontendOTP.ajaxUrl,
						type:'POST',
						data:{
							action:'wawp_send_otp_frontend',
							nonce: wawpFrontendOTP.nonce,
							user_id:uid
						},
						success:function (r) {
							if (r.success) {
								alert( r.data ); } else {
								alert( r.data ); }
						},
						error:function () {
							alert( 'Error sending OTP' ); }
					}
				);
			}
		);
		$( document ).on(
			'click',
			'.wawp-confirm-otp-front',
			function (e) {
				e.preventDefault();
				var uid  = $( this ).data( 'userid' );
				var code = $( this ).prev( '.wawp-otp-code-input' ).val();
				$.ajax(
					{
						url: wawpFrontendOTP.ajaxUrl,
						type:'POST',
						data:{
							action:'wawp_confirm_otp_frontend',
							nonce: wawpFrontendOTP.nonce,
							user_id:uid,
							code:code
						},
						success:function (r) {
							if (r.success) {
								alert( r.data ); location.reload(); } else {
								alert( r.data ); }
						},
						error:function () {
							alert( 'Error confirming OTP' ); }
					}
				);
			}
		);
	}
);
