(function(){var t;t=function(){},"function"==typeof define&&define.amd&&define(t),Djblets.AddIntegrationPopupView=Backbone.View.extend({className:"djblets-c-integrations-popup",integrationTemplateSource:'<li class="djblets-c-integration">\n <a href="<%- addURL %>">\n  <% if (iconSrc) { %>\n   <img class="djblets-c-integration__icon"\n        src="<%- iconSrc %>"\n        srcset="<%- iconSrcSet %>"\n        width="48" height="48" alt="">\n  <% } %>\n  <div class="djblets-c-integration__details">\n   <div class="djblets-c-integration__name"><%- name %></div>\n   <div class="djblets-c-integration__description">\n    <%- description %>\n   </div>\n  </div>\n </a>\n</li>',emptyIntegrationsTemplateSource:`<p class="djblets-c-integrations-popup__empty">\n ${_.escape(gettext("There are no integrations currently installed."))}\n</p>`,initialize(t){this.integrations=t.integrations},render(){const t=this.integrations;if(t.length>0){const e=_.template(this.integrationTemplateSource),i=$("<ul>");for(let n=0;n<t.length;n++)i.append(e(t[n]));this.$el.append(i)}else this.$el.addClass("-is-empty").append(_.template(this.emptyIntegrationsTemplateSource)());return this},remove(){this.hide(),Backbone.View.prototype.remove.call(this)},show(t){const e=$(window),i=this.$el,n=this.el,s=t.position();i.move(s.left,s.top+t.outerHeight(),"absolute").width(100).height(1).show();const o=i.getExtents("b","lr"),l=n.offsetWidth-n.clientWidth-o,a=i.offset(),r=Math.floor(e.height()-a.top-i.getExtents("bm","tb"));if(i.css({height:"auto","max-height":r}),i.hasClass("-is-empty"))i.css("width","auto");else{const t=i.find(".djblets-c-integration").filter(":first").outerWidth(!0),s=e.width(),r=s-a.left-l-i.getExtents("m","r");let d=Math.max(Math.floor(r/t),1)*t+l+o;i.outerWidth(d);0===n.offsetWidth-n.clientWidth-o&&(d-=l,i.outerWidth(d)),a.left+d>s&&i.css("left",s-d)}$(document).one("click.djblets-integrations-popup",()=>this.hide()),$(window).one("resize.djblets-integrations-popup",()=>this.hide())},hide(){this.$el.hide(),$(document).off("click.djblets-integrations-popup"),$(window).off("resize.djblets-integrations-popup")}}),function(){const t=Djblets.Config.ListItem.extend({defaults:_.defaults({removeLabel:gettext("Delete"),showRemove:!0},Djblets.Config.ListItem.prototype.defaults),url(){return this.get("editURL")},parse:t=>({editURL:t.editURL,id:t.id,integrationID:t.integrationID,itemState:t.enabled?"enabled":"disabled",name:t.name})}),e=Djblets.Config.TableItemView.extend({className:"djblets-c-integration-config djblets-c-config-forms-list__item",actionHandlers:{delete:"_onDeleteClicked"},template:_.template('<td class="djblets-c-integration-config__name">\n <img src="<%- iconSrc %>"\n      srcset="<%- iconSrcSet %>"\n      width="32" height="32" alt="">\n <a href="<%- editURL %>"><%- name %></a>\n</td>\n<td class="djblets-c-integration-config__integration-name">\n <%- integrationName %>\n</td>\n<td class="djblets-c-config-forms-list__item-state"></td>\n<td></td>'),getRenderContext(){const t=this.model.get("integrationID"),e=this.model.collection.options.integrationsMap[t];return{iconSrc:e.iconSrc,iconSrcSet:e.iconSrcSet,integrationName:e.name}},async _onDeleteClicked(){await Ink.showConfirmDialog({body:[gettext("This integration will be permanently deleted. This cannot be undone.")],confirmButtonText:gettext("Delete Integration"),isDangerous:!0,onConfirm:async()=>{await this.model.destroy({beforeSend:t=>{t.setRequestHeader("X-CSRFToken",this.model.collection.options.csrfToken)}})},title:gettext("Delete Integration")})}});Djblets.IntegrationConfigListView=Backbone.View.extend({events:{"click .djblets-c-integration-configs__add":"_onAddIntegrationClicked"},addIntegrationPopupViewType:Djblets.AddIntegrationPopupView,listItemType:t,listItemViewType:e,listItemsCollectionType:Djblets.Config.ListItems,listViewType:Djblets.Config.TableView,initialize(t){this._integrationIDs=t.integrationIDs,this._integrationsMap=t.integrationsMap,this.list=new Djblets.Config.List({},{collection:new this.listItemsCollectionType(t.configs,{csrfToken:t.csrfToken,integrationsMap:t.integrationsMap,model:this.listItemType,parse:!0})}),this._popup=null},render(){return this.listView=new this.listViewType({ItemView:this.listItemViewType,el:this.$(".djblets-c-config-forms-list"),model:this.list}),this.listView.render().$el.removeAttr("aria-busy"),this._$listContainer=this.listView.$el.parent(),this.listenTo(this.list.collection,"add remove",this._showOrHideConfigsList),this._showOrHideConfigsList(),this},_showOrHideConfigsList(){this.list.collection.length>0?this._$listContainer.show():this._$listContainer.hide()},_onAddIntegrationClicked(t){if(t.preventDefault(),t.stopPropagation(),!this._popup){const t=this._integrationIDs,e=this._integrationsMap,i=[];for(let n=0;n<t.length;n++)i.push(e[t[n]]);this._popup=new this.addIntegrationPopupViewType({integrations:i}),this._popup.render().$el.appendTo(this.$el)}this._popup.show($(t.target))}})}()}).call(this);
