"use strict";!function(d,l){d(document).ready(function(){if(d(".wq-force-login").length){d(document).on("click",".wq-js-show-register-form",function(e){e.preventDefault();var r=d(e.currentTarget).closest(".wq-force-login");r.find(".wq-js-login-form").hide(),r.find(".wq-js-register-form").fadeIn("fast")}),d(document).on("click",".wq-js-show-login-form",function(e){e.preventDefault();var r=d(e.currentTarget).closest(".wq-force-login");r.find(".wq-js-register-form").hide(),r.find(".wq-js-login-form").fadeIn("fast")}),d(document).on("submit.login",".wq-js-login-form",function(e){return function(e){e.preventDefault();var r=d(e.currentTarget),n=r.closest(".wq-force-action-container"),o=n.closest(".wq-quiz"),i=n.find(".wq-error");l.helpers.showLoading(n),i.html("");var t=r.serializeObject();if(!t.username||!t.password)return i.text(l.i18n.emptyUsernamePassword),void l.helpers.hideLoading(n);var s=l.restUrl+"wp-quiz/v2/login",a=l.helpers.getRequest({url:s,method:"POST",data:t});a.done(function(e){r.find('[name="password"]').val(""),l.helpers.hideLoading(n),e.success?(n.remove(),o.trigger("wp_quiz_complete_force_action")):i.html(e.data)}),a.fail(function(e){console.error(e),r.find('[name="password"]').val(""),l.helpers.hideLoading(n)})}(e)}),d(document).on("submit.register",".wq-js-register-form",function(e){return function(e){e.preventDefault();var r=d(e.currentTarget),n=r.closest(".wq-force-action-container"),o=n.closest(".wq-quiz"),i=n.find(".wq-error");l.helpers.showLoading(n),i.html("");var t=r.serializeObject();if(!(t.username&&t.email&&t.password&&t.password2))return i.text(l.i18n.emptyRequiredFields),void l.helpers.hideLoading(n);if(t.password!==t.password2)return i.text(l.i18n.passwordsNotMatch),void l.helpers.hideLoading(n);var s=l.restUrl+"wp-quiz/v2/register",a=l.helpers.getRequest({url:s,method:"POST",data:t});a.done(function(e){r.find('[name="password"]').val(""),r.find('[name="password2"]').val(""),l.helpers.hideLoading(n),e.success?(n.remove(),o.trigger("wp_quiz_complete_force_action")):i.html(e.data)}),a.fail(function(e){console.error(e),r.find('[name="password"]').val(""),r.find('[name="password2"]').val(""),l.helpers.hideLoading(n)})}(e)})}})}(jQuery,wpQuiz);