import{r as registerInstance,h,H as Host}from"./index-ecdfb761.js";import{A as APIBase}from"./apiBase-6015f41f.js";import"./data-transfer-field-2f305919.js";import"./BaseField-0b01dc2c.js";import"./filter-cbaa3d7d.js";var SepetApi=function(){function e(e,t,i){var s=this;if(t===void 0){t={}}if(i===void 0){i={}}this.createBucket=function(e){return s.api.post("buckets",e)};this.getBuckets=function(){return s.api.get("buckets")};this.getBucket=function(e){return s.api.get("buckets/".concat(e))};this.getBucketVersionList=function(e){return s.api.get("buckets/".concat(e,"/versions"))};this.updateBucket=function(e,t){return s.api.put("buckets/".concat(e),t)};this.deleteBucket=function(e){return s.api.delete("buckets/".concat(e))};this.uploadFile=function(e,t,i){var n=new FormData;n.append(t,i);return s.api.post(e,n)};this.getFileList=function(e,t,i){var n={};if(i){n["bucket-version"]=i}return s.api.get("".concat(e,"/").concat(t),{},n)};this.deleteFileOrFolder=function(e,t){return s.api.delete("".concat(e,"/").concat(t))};this.api=new APIBase(e,t);this.api.axios.defaults.params=i}return e}();var SepetHome=function(){function e(e){var t=this;registerInstance(this,e);this.showFileExplorer=false;this.fileExplorerPath="";this.showDeleteConfirmation=false;this.showItemForm=false;this.listKey=1;this.onClickAddNewItem=function(){return t.showItemForm=true};this.onConfirmDeleteItem=function(){t.isDeletePending=true;t.apiSepet.deleteBucket(t.selectedItem._id).then(t.invalidate).catch(t.onDeleteFail).finally((function(){return t.isDeletePending=false}))};this.onDeleteFail=function(e){var i,s,n,o;if(((i=e.data)===null||i===void 0?void 0:i.error)==="target-group-used-in-load-balancers"){t.deleteErrorMessage="Target group is being used by load balancers ".concat((s=e.data.loadBalancers)===null||s===void 0?void 0:s.map((function(e){return e.name})).join(", "),".")}else if(((n=e.data)===null||n===void 0?void 0:n.error)==="load-balancer-used-in-domains"){t.deleteErrorMessage="Load balancer is being used by domains ".concat((o=e.data.domains)===null||o===void 0?void 0:o.map((function(e){return e.domain})).join(", "),".")}};this.dismissItemFormDialog=function(){t.showItemForm=false;t.selectedItem=undefined};this.dismissDeleteConfirmationDialog=function(){t.showDeleteConfirmation=false;t.selectedItem=undefined;t.deleteErrorMessage=undefined};this.invalidate=function(){t.listKey+=1;t.showItemForm=false;t.showDeleteConfirmation=false;t.selectedItem=undefined;t.deleteErrorMessage=undefined}}e.prototype.componentWillLoad=function(){this.apiSepet=new SepetApi(this.apiEndpoint,this.apiHeaders,this.apiQueryParams)};e.prototype.onAction=function(e){e.stopImmediatePropagation();var t=e.detail;switch(t.name){case"open":{this.showFileExplorer=true;this.selectedItem=t.params.item;this.fileExplorerPath=this.selectedItem.folder;break}case"delete":{this.showDeleteConfirmation=true;this.selectedItem=t.params.item;break}case"edit":{this.showItemForm=true;this.selectedItem=t.params.item;break}}};e.prototype.render=function(){var e=this;var t=this.apiSepet;if(this.showFileExplorer){return h(Host,{class:"d-flex flex-column",style:{minHeight:"calc(100vh - 50px)"}},h("sepet-file-explorer",{apiSepet:t,item:this.selectedItem,onDismissFileExplorer:function(){e.showFileExplorer=false;e.selectedItem=undefined;e.fileExplorerPath=""}}))}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 mb-3"},h("div",{class:"flex-grow-1"},"Buckets"),h("dvn-button",{onClick:this.onClickAddNewItem,leaned:true},"New Bucket"))))),h("sepet-bucket-list",{key:this.listKey,apiSepet:t}),this.showItemForm&&h("dvn-dialog",{shown:true,onDismiss:this.dismissItemFormDialog},h("sepet-bucket-form",{apiSepet: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{SepetHome as sepet_home};