import{r as s,h as i,F as t,H as a}from"./p-a0569a5f.js";import{A as o}from"./p-e476a838.js";import"./p-944da115.js";import"./p-eebad85b.js";import"./p-d343a062.js";class h{constructor(s,i={},t={}){this.createDomain=s=>this.api.post("domains",s),this.getDomains=()=>this.api.get("domains"),this.updateDomain=(s,i)=>this.api.put(`domains/${s}`,i),this.deleteDomain=s=>this.api.delete(`domains/${s}`),this.createLoadBalancer=s=>this.api.post("load-balancers",s),this.getLoadBalancers=()=>this.api.get("load-balancers"),this.updateLoadBalancer=(s,i)=>this.api.put(`load-balancers/${s}`,i),this.deleteLoadBalancer=s=>this.api.delete(`load-balancers/${s}`),this.createTargetGroup=s=>this.api.post("target-groups",s),this.getTargetGroups=()=>this.api.get("target-groups"),this.updateTargetGroup=(s,i)=>this.api.put(`target-groups/${s}`,i),this.deleteTargetGroup=s=>this.api.delete(`target-groups/${s}`),this.getDnsRecord=s=>this.api.post("tools/dns-lookup",{domain:s}),this.api=new o(s,i),this.api.axios.defaults.params=t}}let e=class{constructor(i){s(this,i),this.selectedTab="domains",this.showDeleteConfirmation=!1,this.showItemForm=!1,this.listKey=1,this.onClickAddNewItem=()=>this.showItemForm=!0,this.onConfirmDeleteItem=()=>{let s;"load-balancers"===this.selectedTab?s=this.apiDamga.deleteLoadBalancer(this.selectedItem._id):"target-groups"===this.selectedTab?s=this.apiDamga.deleteTargetGroup(this.selectedItem._id):"domains"===this.selectedTab&&(s=this.apiDamga.deleteDomain(this.selectedItem._id)),this.isDeletePending=!0,null==s||s.then(this.invalidate).catch(this.onDeleteFail).finally((()=>this.isDeletePending=!1))},this.onDeleteFail=s=>{var i,t,a,o;"target-group-used-in-load-balancers"===(null===(i=s.data)||void 0===i?void 0:i.error)?this.deleteErrorMessage=`Target group is being used by load balancers ${null===(t=s.data.loadBalancers)||void 0===t?void 0:t.map((s=>s.name)).join(", ")}.`:"load-balancer-used-in-domains"===(null===(a=s.data)||void 0===a?void 0:a.error)&&(this.deleteErrorMessage=`Load balancer is being used by domains ${null===(o=s.data.domains)||void 0===o?void 0:o.map((s=>s.domain)).join(", ")}.`)},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.apiDamga=new h(this.apiEndpoint,this.apiHeaders,this.apiQueryParams)}onAction(s){s.stopImmediatePropagation();const i=s.detail;switch(i.name){case"delete":this.showDeleteConfirmation=!0,this.selectedItem=i.params.item;break;case"edit":this.showItemForm=!0,this.selectedItem=i.params.item}}render(){const{apiDamga:s,selectedTab:o}=this,h={domains:"Domain","load-balancers":"Load Balancer","target-groups":"Target Group"};return i(a,{class:"d-flex flex-column",style:{minHeight:"calc(100vh - 50px)"}},i("div",{class:"container"},i("div",{class:"row"},i("div",{class:"col-sm-12"},i("div",{class:"d-flex align-items-center"},i("div",{class:"flex-grow-1"},i("dvn-menu",{orientation:"horizontal"},[{label:"Domains",value:"domains"},{label:"Load Balancers",value:"load-balancers"},{label:"Target Groups",value:"target-groups"}].map((({label:s,value:t})=>i("dvn-menu-item",{highlighted:t===o,onClick:()=>this.selectedTab=t},s))))),h[o]&&i("dvn-button",{onClick:this.onClickAddNewItem},"New ",h[o]))))),"domains"===o&&i(t,null,i("damga-domain-list",{key:this.listKey,apiDamga:s}),this.showItemForm&&i("dvn-dialog",{shown:!0,onDismiss:this.dismissItemFormDialog},i("damga-domain-form",{apiDamga:s,onChange:this.invalidate,item:this.selectedItem}))),"load-balancers"===o&&i(t,null,i("damga-load-balancer-list",{key:this.listKey,apiDamga:s}),this.showItemForm&&i("dvn-dialog",{shown:!0,onDismiss:this.dismissItemFormDialog},i("damga-load-balancer-form",{apiDamga:s,onChange:this.invalidate,item:this.selectedItem}))),"target-groups"===o&&i(t,null,i("damga-target-group-list",{key:this.listKey,apiDamga:s}),this.showItemForm&&i("dvn-dialog",{shown:!0,onDismiss:this.dismissItemFormDialog},i("damga-target-group-form",{apiDamga:s,onChange:this.invalidate,item:this.selectedItem}))),this.showDeleteConfirmation&&i("dvn-dialog",{shown:!0,onDismiss:this.dismissDeleteConfirmationDialog,title:"Deletion"},i("p",null,"Are you sure to delete this item? This action cannot be undone."),this.deleteErrorMessage&&i("p",{class:"text-danger"},this.deleteErrorMessage),i("div",{slot:"actions"},i("dvn-button",{view:"flat",onClick:this.dismissDeleteConfirmationDialog},"Cancel"),i("dvn-button",{tint:"danger",disabled:this.isDeletePending,progressing:this.isDeletePending,onClick:this.onConfirmDeleteItem},"Yes, Delete"))))}};export{e as damga_home}