!function(e){formintorjs.define(["admin/settings/toggle-container","text!tpl/fields.html"],function(t,i){return t.extend({multiple:!1,events:{"click .wpmudev-multiresult--add":"add_result","click .wpmudev-delete-result":"delete_result","click .wpmudev-preview--image":"add_image","click .wpmudev-open_media":"add_image","click .wpmudev-url--clear":"clear_image","change .wpmudev-result-title":"update_title","change .wpmudev-result-image":"update_image","change .wpmudev-result-descrition":"update_description"},className:"wpmudev-option",init:function(){this.results=this.model.get("results"),this.listenTo(Forminator.Events,"forminator:quiz:results:order:updated",this.render)},render:function(){this.$el.html(""),this.$el.append(this.get_label_html()),this.$el.append(this.get_field_html());this.get_saved_value();this.results.length&&this.$el.find(".wpmudev-multiresult").addClass("wpmudev-has_results"),this.trigger("rendered",this.get_value()),this.on_render()},get_field_html:function(){var t=this.get_values_html();return Forminator.Utils.template(e(i).find("#settings-field-result-list-tpl").html())({childs:t})},get_values_html:function(){var e=this;return this.results.map(function(t,i){return e.get_value_html(t,i)}).join(" ")},get_value_html:function(t,l){this.get_saved_value();return Forminator.Utils.template(e(i).find("#settings-field-result-list-row-tpl").html())({row:t.toJSON(),index:l})},add_result:function(e){e.preventDefault(),new_result=new Forminator.Models.Result({}),new_result.set("order",this.results.length),this.results.add(new_result,{silent:!0}),this.update(),this.render()},delete_result:function(t){t.preventDefault();var i=e(t.target),l=this.get_model(i);this.results.remove(l,{silent:!0}),this.update(),this.render()},get_index:function(e){return e.closest(".wpmudev-multiresult--item").data("index")},get_model:function(e){var t=this.get_index(e);return this.results.get_by_index(t)},update_title:function(t){var i=this.get_model(e(t.target));value=e(t.target).val(),i.set("title",value),i.set("slug",Forminator.Utils.get_slug(value)),this.update()},update_image:function(t){var i=this.get_model(e(t.target));value=e(t.target).val(),i.set("image",value),this.render()},update_description:function(t){var i=this.get_model(e(t.target));value=e(t.target).val(),i.set("description",value)},add_image:function(t){t.preventDefault();var i=this,l=wp.media({title:this.options.popup_label,button:{text:this.options.popup_button_label},multiple:!1}).on("select",function(){var s,r=i.get_model(e(t.target)),u=l.state().get("selection").first().toJSON(),n=e(t.target).closest(".wpmudev-multiresult--item"),a=n.find(".wpmudev-browse--preview"),d=n.find(".wpmudev-get_image"),o=n.find(".wpmudev-url--input");u&&u.url&&(a.addClass("wpmudev-has_image"),s=_.isUndefined(u.sizes.full.url)?u.url:u.sizes.full.url,d.css("background-image","url({url})".replace("{url}",u.sizes.thumbnail.url)),o.val("{url}".replace("{url}",s)),r.set("image",s))});l.open()},clear_image:function(t){this.get_model(e(t.target)).set("image",""),this.render()},update:function(){Forminator.Events.trigger("forminator:quiz:results:updated")}})})}(jQuery);