"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 n=Object.getOwnPropertyDescriptor(e,r);if(void 0===n){var a=Object.getPrototypeOf(e);return null===a?void 0:t(a,r,s)}if("value"in n)return n.value;var i=n.get;return void 0!==i?i.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(s,a){function i(){return _classCallCheck(this,i),_possibleConstructorReturn(this,(i.__proto__||Object.getPrototypeOf(i)).apply(this,arguments))}s.Personality=(_inherits(i,s.Trivia),_createClass(i,[{key:"initTemplates",value:function(){_get(i.prototype.__proto__||Object.getPrototypeOf(i.prototype),"initTemplates",this).call(this),this.templates.answerResult=wp.template("wp-quiz-personality-answer-result-tpl")}},{key:"getAnswerTmplData",value:function(t,e,r){return{answer:t,baseName:r,index:e,results:this.store.results,i18n:s.i18n}}},{key:"loadEvents",value:function(){var n=this;_get(i.prototype.__proto__||Object.getPrototypeOf(i.prototype),"loadEvents",this).call(this),this.$wrapper.on("change",".wp-quiz-result-title",function(t){var e=a(t.currentTarget),r=e.val(),s=e.closest(".wp-quiz-result").attr("data-id");n.store.results[s].title=r,n.$wrapper.find('.wp-quiz-answer-result[data-id="'+s+'"]').find(".wp-quiz-answer-result-title").text(r)})}},{key:"addedAnswer",value:function(t,s){var n="",a=this.templates.answerResult,i=t.find(".wp-quiz-answer-results");Object.values(this.store.results).forEach(function(t,e){t.point=s.results[t.id]?s.results[t.id]:"";var r={result:t,baseName:i.attr("data-base-name")};n+=a(r)}),i.append(n)}},{key:"addResult",value:function(t,e,r){_get(i.prototype.__proto__||Object.getPrototypeOf(i.prototype),"addResult",this).call(this,t,e,r),this.store.results[this.tracker.lastAddedResult.id]=this.tracker.lastAddedResult;var s=this.templates.answerResult,n={result:this.tracker.lastAddedResult,baseName:""};this.$wrapper.find(".wp-quiz-answer-results").each(function(){if(!a(this).find('.wp-quiz-answer-result[data-id="'+n.result.id+'"]').length){var t=a(this).attr("data-answer-results")?JSON.parse(a(this).attr("data-answer-results")):{},e=a(this).attr("data-base-name");n.result.point=t[n.result.id]?t[n.result.id]:"",n.baseName=e,a(this).append(s(n))}})}},{key:"removeResult",value:function(t){_get(i.prototype.__proto__||Object.getPrototypeOf(i.prototype),"removeResult",this).call(this,t),delete this.store.results[this.tracker.lastRemovedResultId],this.$wrapper.find('.wp-quiz-answer-result[data-id="'+this.tracker.lastRemovedResultId+'"]').remove()}},{key:"name",get:function(){return"personality"}},{key:"videoUpload",get:function(){return!0}},{key:"questionMediaType",get:function(){return!0}},{key:"answerType",get:function(){return!0}}]),i),a(document).ready(function(){a('.wp-quiz-backend[data-type="personality"]').each(function(){new s.Personality(a(this))})})}(wpQuizAdmin,jQuery);