"use strict";var _createClass=function(){function s(t,e){for(var r=0;r<e.length;r++){var s=e[r];s.enumerable=s.enumerable||!1,s.configurable=!0,"value"in s&&(s.writable=!0),Object.defineProperty(t,s.key,s)}}return function(t,e,r){return e&&s(t.prototype,e),r&&s(t,r),t}}(),_get=function t(e,r,s){null===e&&(e=Function.prototype);var i=Object.getOwnPropertyDescriptor(e,r);if(void 0===i){var n=Object.getPrototypeOf(e);return null===n?void 0:t(n,r,s)}if("value"in i)return i.value;var a=i.get;return void 0!==a?a.call(s):void 0};function _classCallCheck(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function _possibleConstructorReturn(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}function _inherits(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}!function(o,i){var e=function(t){function s(t,e){_classCallCheck(this,s);var r=_possibleConstructorReturn(this,(s.__proto__||Object.getPrototypeOf(s)).call(this,t,e));return r.checkedAnswersList="",r}return _inherits(s,o.Quiz),_createClass(s,[{key:"isFullyAnswered",value:function(t){var e=t.attr("data-index");return parseInt(this.questions[e].totalCorrects)<=t.find(".wq-answer.chosen").length}},{key:"afterClickAnswer",value:function(t,e){"multiple"!==this.settings.question_layout&&"off"!==this.settings.end_answers||this.checkQuestion(e),_get(s.prototype.__proto__||Object.getPrototypeOf(s.prototype),"afterClickAnswer",this).call(this,t,e)}},{key:"checkQuestion",value:function(s){var i=this,t=s.attr("data-index"),n=this.questions[t];if(n){var a=0<s.find(".wq-answer.chosen").length;this.checkedAnswersList+="<div><p><strong>"+n.title+"</strong></p>",Object.keys(n.answers).forEach(function(t){var e=n.answers[t],r=s.find('.wq-answer[data-id="'+t+'"]');e.isCorrect&&parseInt(e.isCorrect)?r.addClass("wq_correctAnswer"):r.hasClass("chosen")&&(r.addClass("wq_incorrectAnswer"),a=!1),r.hasClass("chosen")&&(i.checkedAnswersList+='<p class="'+(a?"is-correct":"is-incorrect")+'">'+e.title+"</p>"),"on"===i.settings.end_answers&&"multiple"===i.settings.question_layout&&r.removeClass("wq_correctAnswer").removeClass("wq_incorrectAnswer")}),this.checkedAnswersList+="</div>",a?(this.totalCorrects++,s.addClass("is-correct")):s.addClass("is-incorrect"),("off"===this.settings.end_answers||"single"===this.settings.question_layout||s.find(".wq-trivia-question-explanation").length)&&s.find(".wq-trivia-question-explanation").fadeIn()}}},{key:"trackAnswer",value:function(t){var e=t.attr("data-index"),r=this.questions[e],s={answers:[]};t.find(".wq-answer.chosen").each(function(t,e){return s.answers.push(e.dataset.id)}),this.tracker[r.id]=s}},{key:"complete",value:function(){var t=this;"single"===this.settings.question_layout&&"on"===this.settings.end_answers&&this.$wrapper.find(".wq-question").each(function(){t.checkQuestion(i(this))}),_get(s.prototype.__proto__||Object.getPrototypeOf(s.prototype),"complete",this).call(this)}},{key:"findResultId",value:function(){var e=this,r=this.totalCorrects,s=!1;this.results.forEach(function(t){s||r>=t.min&&r<=t.max&&(s=!0,e.resultId=t.id,e.result=t)})}},{key:"showResult",value:function(){var t=this,e=this.totalCorrects,r=this.totalQuestions;if(this.result.redirect_url)setTimeout(function(){window.location.href=t.result.redirect_url.replace("%%score%%",e).replace("%%total%%",r)},this.explanationDelay);else{var s=this.$wrapper.find(".wq-results"),i=this.$wrapper.find('.wq-result[data-id="'+this.resultId+'"]'),n=o.i18n.resultScore.replace("%%score%%",e).replace("%%total%%",r),a=this.$wrapper.find('.wq-question[data-index="'+this.lastQuestionIndex+'"]');i.find(".wq-result-score").text(n),i.find(".wq-checked-answers-list").html(this.checkedAnswersList),i.show(),"multiple"===this.settings.question_layout&&a.is(":visible")?a.animateCss(this.settings.animation_out,function(){a.hide();a.offset().top;a.hide(),s.show().animateCss(t.settings.animation_in)}):("on"===this.settings.end_answers&&this.scrollToQuestion(0),s.show())}}},{key:"savePlayData",value:function(){var e=this,t=o.restUrl+"wp-quiz/v2/play_data",r=o.helpers.getRequest({url:t,method:"POST",data:{quiz_id:this.quizId,quiz_data:JSON.stringify(this.quizData),answered:JSON.stringify(this.tracker),corrects:this.totalCorrects,result_id:this.resultId,current_url:window.location.href}});r.done(function(t){"number"==typeof t&&(e.$wrapper.find(".wq-subscribe-form").attr("data-tracking-id",t),e.$wrapper.find(".wq-share button").attr("data-tracking-id",t),i(".mfp-wrap .wq-popup .wq-share button").attr("data-tracking-id",t),e.$wrapper.find(".wq_forceShareFB").attr("data-tracking-id",t))}),r.fail(function(t){console.error(t)})}},{key:"restartQuiz",value:function(){_get(s.prototype.__proto__||Object.getPrototypeOf(s.prototype),"restartQuiz",this).call(this),this.$wrapper.find(".wq_correctExplanationHead").removeClass("wq_correctExplanationHead"),this.$wrapper.find(".wq_wrongExplanationHead").removeClass("wq_wrongExplanationHead"),this.$wrapper.find(".wq_incorrectAnswer").removeClass("wq_incorrectAnswer"),this.$wrapper.find(".wq_correctAnswer").removeClass("wq_correctAnswer"),this.checkedAnswersList="",this.$wrapper.find(".wq-checked-answers-list").html("")}}]),s}();i(document).ready(function(){i(".wq-quiz-trivia").each(function(){var t=i(this).attr("data-quiz-id");void 0!==window["triviaQuiz"+t]&&new e(i(this),window["triviaQuiz"+t])})})}(wpQuiz,jQuery);