!function(t){formintorjs.define(["admin/settings/toggle-container","text!tpl/fields.html"],function(e,i){return e.extend({multiple:!1,events:{"click .wpmudev-open_media":"add_image","click .wpmudev-add-variation":"add_option","click .wpmudev-action--kill":"delete_option","click .wpmudev-label-list-variations":"click_variation_label","change .wpmudev-add-name":"update_label","change .wpmudev-add-price":"update_value","change #list-all-variations":"update_list"},className:"wpmudev-option",render:function(){this.$el.html(""),this.$el.append(this.get_label_html()),this.$el.append(this.get_field_html());var t=this.get_saved_value()||[];_.isEmpty(t)||this.$el.find(".wpmudev-multiproduct").addClass("wpmudev-has_products"),this.trigger("rendered",this.get_value()),this.on_render()},get_field_html:function(){var e=this.get_values_html();return Forminator.Utils.template(t(i).find("#settings-field-product-multiple-tpl").html())({childs:e,list_variations:this.model.get("list_variations")||!1})},get_values_html:function(){var t=this.get_saved_value()||[];return _.map(t,this.get_value_html,this).join("")},get_value_html:function(e,a){this.get_saved_value();return Forminator.Utils.template(t(i).find("#settings-field-product-multiple-row-tpl").html())({row:e,index:a})},update_label:function(e){var i=t(e.target).closest(".wpmudev-list--item").data("index"),a=t(e.target).val(),l=this.get_saved_value()||[];l[i].label=a,this.save_value(l),this.trigger("updated",l)},update_value:function(e){var i=t(e.target).closest(".wpmudev-list--item").data("index"),a=t(e.target).val(),l=this.get_saved_value()||[];l[i].value=a,this.save_value(l),this.trigger("updated",l)},add_option:function(t){var e=this.get_saved_value()||[];e.push({label:"",value:"",image:""}),this.save_value(e),this.trigger("updated",e),this.render()},delete_option:function(e){var i=t(e.target).closest(".wpmudev-list--item").data("index"),a=this.get_saved_value()||[];a.splice(i,1),this.save_value(a),this.trigger("updated",a),this.render()},update_list:function(e){e.preventDefault(),t(e.target).is(":checked")?this.model.set("list_variations",!0):this.model.set("list_variations",!1)},click_variation_label:function(t){t.preventDefault(),t.stopPropagation(),t.stopImmediatePropagation(),this.$el.find("#list-all-variations").click()},add_image:function(e){e.preventDefault();var i=this,a=wp.media({title:this.options.popup_label,button:{text:this.options.popup_button_label},multiple:!1}).on("select",function(){var l=a.state().get("selection").first().toJSON(),s=t(e.target).closest(".wpmudev-list--item"),d=s.find(".wpmudev-browse--preview"),n=s.find(".wpmudev-get_image"),u=s.find(".wpmudev-url--input");if(l&&l.url){d.addClass("wpmudev-has_image"),n.css("background-image","url({url})".replace("{url}",l.url)),u.val("{url}".replace("{url}",l.url));var r=t(e.target).closest(".wpmudev-list--item").data("index"),v=(t(e.target).val(),i.get_saved_value()||[]);v[r].image=l.url,i.save_value(v),i.trigger("updated",v)}});a.open()}})})}(jQuery);