import{r as s,h as t,H as i}from"./p-9f21f85f.js";import{A as e}from"./p-25d382ec.js";import"./p-3968aca6.js";import"./p-105f7627.js";import"./p-d343a062.js";class h{constructor(s,t={},i={}){this.createBucket=s=>this.api.post("buckets",s),this.getBuckets=()=>this.api.get("buckets"),this.getBucket=s=>this.api.get(`buckets/${s}`),this.getBucketVersionList=s=>this.api.get(`buckets/${s}/versions`),this.updateBucket=(s,t)=>this.api.put(`buckets/${s}`,t),this.deleteBucket=s=>this.api.delete(`buckets/${s}`),this.uploadFile=(s,t,i)=>{const e=new FormData;return e.append(t,i),this.api.post(s,e)},this.getFileList=(s,t,i)=>{const e={};return i&&(e["bucket-version"]=i),this.api.get(`${s}/${t}`,{},e)},this.deleteFileOrFolder=(s,t)=>this.api.delete(`${s}/${t}`),this.api=new e(s,t),this.api.axios.defaults.params=i}}const o=class{constructor(t){s(this,t),this.showFileExplorer=!1,this.fileExplorerPath="",this.showDeleteConfirmation=!1,this.showItemForm=!1,this.listKey=1,this.onClickAddNewItem=()=>this.showItemForm=!0,this.onConfirmDeleteItem=()=>{this.isDeletePending=!0,this.apiSepet.deleteBucket(this.selectedItem._id).then(this.invalidate).catch(this.onDeleteFail).finally((()=>this.isDeletePending=!1))},this.onDeleteFail=s=>{var t,i,e,h;"target-group-used-in-load-balancers"===(null===(t=s.data)||void 0===t?void 0:t.error)?this.deleteErrorMessage=`Target group is being used by load balancers ${null===(i=s.data.loadBalancers)||void 0===i?void 0:i.map((s=>s.name)).join(", ")}.`:"load-balancer-used-in-domains"===(null===(e=s.data)||void 0===e?void 0:e.error)&&(this.deleteErrorMessage=`Load balancer is being used by domains ${null===(h=s.data.domains)||void 0===h?void 0:h.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.apiSepet=new h(this.apiEndpoint,this.apiHeaders,this.apiQueryParams)}onAction(s){s.stopImmediatePropagation();const t=s.detail;switch(t.name){case"open":this.showFileExplorer=!0,this.selectedItem=t.params.item,this.fileExplorerPath=this.selectedItem.folder;break;case"delete":this.showDeleteConfirmation=!0,this.selectedItem=t.params.item;break;case"edit":this.showItemForm=!0,this.selectedItem=t.params.item}}render(){const{apiSepet:s}=this;return this.showFileExplorer?t(i,{class:"d-flex flex-column",style:{minHeight:"calc(100vh - 50px)"}},t("sepet-file-explorer",{apiSepet:s,item:this.selectedItem,onDismissFileExplorer:()=>{this.showFileExplorer=!1,this.selectedItem=void 0,this.fileExplorerPath=""}})):t(i,{class:"d-flex flex-column",style:{minHeight:"calc(100vh - 50px)"}},t("div",{class:"container"},t("div",{class:"row"},t("div",{class:"col-sm-12"},t("div",{class:"d-flex align-items-center mb-3"},t("div",{class:"flex-grow-1"},"Buckets"),t("dvn-button",{onClick:this.onClickAddNewItem,leaned:!0},"New Bucket"))))),t("sepet-bucket-list",{key:this.listKey,apiSepet:s}),this.showItemForm&&t("dvn-dialog",{shown:!0,onDismiss:this.dismissItemFormDialog},t("sepet-bucket-form",{apiSepet:s,onChange:this.invalidate,item:this.selectedItem})),this.showDeleteConfirmation&&t("dvn-dialog",{shown:!0,onDismiss:this.dismissDeleteConfirmationDialog,title:"Deletion"},t("p",null,"Are you sure to delete this item? This action cannot be undone."),this.deleteErrorMessage&&t("p",{class:"text-danger"},this.deleteErrorMessage),t("div",{slot:"actions"},t("dvn-button",{view:"flat",onClick:this.dismissDeleteConfirmationDialog},"Cancel"),t("dvn-button",{tint:"danger",disabled:this.isDeletePending,progressing:this.isDeletePending,onClick:this.onConfirmDeleteItem},"Yes, Delete"))))}};export{o as sepet_home}