import{r as i,h as s,F as t,H as e}from"./p-9f21f85f.js";import{K as l}from"./p-03b520ca.js";import"./p-e78d5616.js";import"./p-3968aca6.js";import"./p-105f7627.js";import"./p-d343a062.js";const h=[{label:"Users",value:"users"},{label:"API Keys",value:"api-keys"},{label:"SAML Configs",value:"saml-configs"}],n={"api-keys":"API Key","saml-configs":"SAML Config"},o=class{constructor(s){i(this,s),this.selectedTab="saml-configs",this.showDeleteConfirmation=!1,this.showItemForm=!1,this.listKey=1,this.onClickAddNewItem=()=>this.showItemForm=!0,this.onConfirmDeleteItem=()=>{let i;"api-keys"===this.selectedTab?i=this.apiKimlik.deleteApiKey(this.selectedItem._id):"saml-configs"===this.selectedTab&&(i=this.apiKimlik.deleteSAMLConfig(this.selectedItem._id)),this.isDeletePending=!0,null==i||i.then(this.invalidate).catch(this.onDeleteFail).finally((()=>this.isDeletePending=!1))},this.onDeleteFail=()=>{this.deleteErrorMessage="Unexpected error."},this.dismissItemFormDialog=()=>{this.showItemForm=!1,this.selectedItem=void 0},this.dismissDeleteConfirmationDialog=()=>{this.showDeleteConfirmation=!1,this.selectedItem=void 0,this.deleteErrorMessage=void 0},this.invalidate=()=>{this.listKey+=1,this.showItemForm=!1,this.showDeleteConfirmation=!1,this.selectedItem=void 0,this.deleteErrorMessage=void 0}}componentWillLoad(){this.apiKimlik=new l(this.apiEndpoint,this.apiHeaders)}onAction(i){i.stopImmediatePropagation();const s=i.detail;switch(s.name){case"delete":this.showDeleteConfirmation=!0,this.selectedItem=s.params.item;break;case"edit":this.showItemForm=!0,this.selectedItem=s.params.item}}render(){const{apiKimlik:i,selectedTab:l}=this;return s(e,{class:"d-flex flex-column",style:{minHeight:"calc(100vh - 50px)"}},s("div",{class:"container"},s("div",{class:"row"},s("div",{class:"col-sm-12"},s("div",{class:"d-flex align-items-center"},s("div",{class:"flex-grow-1"},s("dvn-menu",{orientation:"horizontal"},h.map((({label:i,value:t})=>s("dvn-menu-item",{highlighted:t===l,onClick:()=>this.selectedTab=t},i))))),n[l]&&s("dvn-button",{onClick:this.onClickAddNewItem},"New ",n[l]))))),"users"===l&&s(t,null,s("kimlik-user-list",{key:this.listKey,apiKimlik:i})),"api-keys"===l&&s(t,null,s("kimlik-api-key-list",{key:this.listKey,apiKimlik:i}),this.showItemForm&&s("dvn-dialog",{shown:!0,onDismiss:this.dismissItemFormDialog},s("kimlik-api-key-form",{apiKimlik:i,onChange:this.invalidate,item:this.selectedItem}))),"saml-configs"===l&&s(t,null,s("kimlik-saml-config-list",{key:this.listKey,apiKimlik:i}),this.showItemForm&&s("dvn-dialog",{shown:!0,onDismiss:this.dismissItemFormDialog},s("kimlik-saml-config-form",{apiKimlik:i,onChange:this.invalidate,item:this.selectedItem}))),this.showDeleteConfirmation&&s("dvn-dialog",{shown:!0,onDismiss:this.dismissDeleteConfirmationDialog,title:"Deletion"},s("p",null,"Are you sure to delete this item? This action cannot be undone."),this.deleteErrorMessage&&s("p",{class:"text-danger"},this.deleteErrorMessage),s("div",{slot:"actions"},s("dvn-button",{view:"flat",onClick:this.dismissDeleteConfirmationDialog},"Cancel"),s("dvn-button",{tint:"danger",disabled:this.isDeletePending,progressing:this.isDeletePending,onClick:this.onConfirmDeleteItem},"Yes, Delete"))))}};export{o as kimlik_home}