!function(){"use strict";jQuery(e=>{const t=_glsr_deactivate,s=Backbone.Model.extend({defaults:{details:"",name:"",reason:"",slug:"",version:""}}),i=Backbone.Collection.extend({model:s}),a=Backbone.View.extend({className:"glsr-dp-overlay",isBusy:!1,model:null,target:null,template:null,events:{click:"closeOverlay","click .expand-info":"expandDetails","click .glsr-dp-reason":"selectReason","click .submit":"submit",'input input[name="reason"]':"updateModel",'input textarea[name="details"]':"updateModel"},initialize:function(e){_.extend(this,_.pick(e,"target")),this.template=wp.template("glsr-deativate")},render:function(){let e=_.extend({},this.model.toJSON(),t,{action:this.target.attr("href")});return this.$el.html(this.template(e)),this.containFocus(),this},closeOverlay:function(t){(27===event.keyCode||e(t.target).is(".close")||e(t.target).is(".deactivate")||e(t.target).is(".glsr-dp-backdrop"))&&(e("body").addClass("closing-overlay"),this.$el.fadeOut(130,()=>{e("body").removeClass("closing-overlay"),e("body").removeClass("modal-open"),this.remove(),this.unbind(),this.target&&this.target.trigger("focus")}))},containFocus:function(){_.delay(()=>e(".glsr-dp-overlay").trigger("focus"),100),this.$el.on("keydown.glsr",e=>{const t=this.$el.find(".glsr-dp-header button").first(),s=this.$el.find(".glsr-dp-footer a").last();9===e.which&&(t[0]===e.target&&e.shiftKey?(s.trigger("focus"),e.preventDefault()):s[0]!==e.target||e.shiftKey||(t.trigger("focus"),e.preventDefault()))})},expandDetails:function(){this.$("#glsr-dp-info").slideToggle("fast")},onChange:function(e){this.isBusy||this.updateModel(e.currentTarget)},selectReason:function(t){const s=e(t.currentTarget),i=s.data("placeholder"),a=this.$(".glsr-dp-help"),n=s.find("input").val(),l=["feature-missing"],o=["confused","looking-for-different","not-working"];this.$(".glsr-dp-reason").removeClass("is-selected"),this.$(".glsr-dp-details textarea").attr("placeholder",i),this.$(".glsr-dp-details")[""===i?"slideUp":"slideDown"]("fast"),s.toggleClass("is-selected"),~[].concat(l,o).indexOf(n)?(a.find(".is-info")[~l.indexOf(n)?"show":"hide"](),a.find(".is-warning")[~o.indexOf(n)?"show":"hide"](),a.slideDown("fast")):a.slideUp("fast")},submit:function(s){s.preventDefault();const i={[t.ajax.prefix]:_.extend({},this.model.toJSON(),{_action:"deactivate",_nonce:t.ajax.nonce})};e(s.currentTarget).addClass("is-busy").prop("disabled",!0).text(t.l10n.processing),wp.ajax.post(t.ajax.action,i).always(()=>{window.location.href=this.target.attr("href")})},updateModel:function(e){this.isBusy||(this.isBusy=!0,this.model.set(e.target.name,e.target.value,{validate:!1}),this.isBusy=!1)}});new(Backbone.View.extend({el:"#the-list",collection:null,overlay:e("#glsr-dp-overlay"),events:{"click a[data-deactivate]":"openOverlay"},initialize:function(){this.collection=new i(t.plugins)},openOverlay:function(t){let s=e(t.target),i=s.data("deactivate"),n=this.collection.findWhere({slug:i});if(n){let i=new a({model:n,target:s});t.preventDefault(),e("body").addClass("modal-open"),i.render(),this.overlay.html(i.el)}}}))})}();
