import{r as registerInstance,h,F as Fragment,H as Host}from"./index-ecdfb761.js";import{K as KimlikApiImpl}from"./kimlik-api-66e341bd.js";import"./apiBase-648a161d.js";import"./data-transfer-field-2f305919.js";import"./BaseField-0b01dc2c.js";import"./filter-cbaa3d7d.js";var tabs=[{label:"Users",value:"users"},{label:"API Keys",value:"api-keys"},{label:"SAML Configs",value:"saml-configs"}];var newItemLabels={"api-keys":"API Key","saml-configs":"SAML Config"};var KimlikHome=function(){function e(e){var i=this;registerInstance(this,e);this.selectedTab="saml-configs";this.showDeleteConfirmation=false;this.showItemForm=false;this.listKey=1;this.onClickAddNewItem=function(){return i.showItemForm=true};this.onConfirmDeleteItem=function(){var e;if(i.selectedTab==="api-keys"){e=i.apiKimlik.deleteApiKey(i.selectedItem._id)}else if(i.selectedTab==="saml-configs"){e=i.apiKimlik.deleteSAMLConfig(i.selectedItem._id)}i.isDeletePending=true;e===null||e===void 0?void 0:e.then(i.invalidate).catch(i.onDeleteFail).finally((function(){return i.isDeletePending=false}))};this.onDeleteFail=function(e){i.deleteErrorMessage="Unexpected error."};this.dismissItemFormDialog=function(){i.showItemForm=false;i.selectedItem=undefined};this.dismissDeleteConfirmationDialog=function(){i.showDeleteConfirmation=false;i.selectedItem=undefined;i.deleteErrorMessage=undefined};this.invalidate=function(){i.listKey+=1;i.showItemForm=false;i.showDeleteConfirmation=false;i.selectedItem=undefined;i.deleteErrorMessage=undefined}}e.prototype.componentWillLoad=function(){this.apiKimlik=new KimlikApiImpl(this.apiEndpoint,this.apiHeaders)};e.prototype.onAction=function(e){e.stopImmediatePropagation();var i=e.detail;switch(i.name){case"delete":{this.showDeleteConfirmation=true;this.selectedItem=i.params.item;break}case"edit":{this.showItemForm=true;this.selectedItem=i.params.item;break}}};e.prototype.render=function(){var e=this;var i=this,t=i.apiKimlik,s=i.selectedTab;return h(Host,{class:"d-flex flex-column",style:{minHeight:"calc(100vh - 50px)"}},h("div",{class:"container"},h("div",{class:"row"},h("div",{class:"col-sm-12"},h("div",{class:"d-flex align-items-center"},h("div",{class:"flex-grow-1"},h("dvn-menu",{orientation:"horizontal"},tabs.map((function(i){var t=i.label,n=i.value;return h("dvn-menu-item",{highlighted:n===s,onClick:function(){return e.selectedTab=n}},t)})))),newItemLabels[s]&&h("dvn-button",{onClick:this.onClickAddNewItem},"New ",newItemLabels[s]))))),s==="users"&&h(Fragment,null,h("kimlik-user-list",{key:this.listKey,apiKimlik:t})),s==="api-keys"&&h(Fragment,null,h("kimlik-api-key-list",{key:this.listKey,apiKimlik:t}),this.showItemForm&&h("dvn-dialog",{shown:true,onDismiss:this.dismissItemFormDialog},h("kimlik-api-key-form",{apiKimlik:t,onChange:this.invalidate,item:this.selectedItem}))),s==="saml-configs"&&h(Fragment,null,h("kimlik-saml-config-list",{key:this.listKey,apiKimlik:t}),this.showItemForm&&h("dvn-dialog",{shown:true,onDismiss:this.dismissItemFormDialog},h("kimlik-saml-config-form",{apiKimlik:t,onChange:this.invalidate,item:this.selectedItem}))),this.showDeleteConfirmation&&h("dvn-dialog",{shown:true,onDismiss:this.dismissDeleteConfirmationDialog,title:"Deletion"},h("p",null,"Are you sure to delete this item? This action cannot be undone."),this.deleteErrorMessage&&h("p",{class:"text-danger"},this.deleteErrorMessage),h("div",{slot:"actions"},h("dvn-button",{view:"flat",onClick:this.dismissDeleteConfirmationDialog},"Cancel"),h("dvn-button",{tint:"danger",disabled:this.isDeletePending,progressing:this.isDeletePending,onClick:this.onConfirmDeleteItem},"Yes, Delete"))))};return e}();export{KimlikHome as kimlik_home};