import{r as t,h as i,H as s}from"./p-9f21f85f.js";import{T as e}from"./p-968ee2ec.js";import{M as a}from"./p-0b1ac773.js";import{V as o}from"./p-ad6da9fe.js";import{p as n}from"./p-d1fe7ec4.js";import{D as r}from"./p-fab6a555.js";import{A as d}from"./p-e78d5616.js";import"./p-31e77e7b.js";import"./p-105f7627.js";import"./p-35c7f358.js";import"./p-3968aca6.js";import"./p-d343a062.js";class l{constructor(t,i={},s={}){this.getProxyAnalyses=(t,i,s,e)=>this.api.get("analyses",{domains:t.join(","),startDate:i,endDate:s,timeInterval:e}),this.getLogs=(t,i,s)=>this.api.get("logs",{domain:t,startDate:i,endDate:s}),this.api=new d(t,i),this.api.axios.defaults.params=s}}const h=class{constructor(s){t(this,s),this.showEditProductForm=!1,this.showDeleteConfirmation=!1,this.fetchProduct=async()=>{const{id:t}=this.match.params;this.product=await this.apiDevingen.getProduct(t).catch((t=>this.error=t))},this.renderHeader=()=>{var t;return i("div",{class:"container"},i("div",{class:"row"},i("div",{class:"col d-flex align-items-center pt-2 pb-3"},i("h2",{class:"m-0"},null===(t=this.product)||void 0===t?void 0:t.name),i("dvn-icon-button",{iconName:"uil uil-cog",scale:"small",view:"flat",onClick:()=>this.showEditProductForm=!0}))))},this.renderEditProductForm=()=>this.showEditProductForm?i("dvn-dialog",{shown:!0,onDismiss:()=>this.showEditProductForm=!1},i("doldurma-form",{fields:[new e("name","Name").addInterceptor("onSubmit",new o(2,32)).addInterceptor("onSubmit",new a).setValue(this.product.name).require()],onSubmit:this.onSubmitEditProductForm,submitButtonLabel:"Update",extraButtons:[{label:"Delete",tint:"danger",view:"flat",onClick:()=>{this.showDeleteConfirmation=!0}}],formErrors:this.updateError?["Update failed."]:void 0})):null,this.renderDeleteProductConfirmation=()=>{var t;return this.showDeleteConfirmation?i("dvn-dialog",{shown:!0,onDismiss:()=>{this.showDeleteConfirmation=!1,this.deleteError=void 0},title:"Deletion"},i("p",null,"Are you sure to delete this product? This action cannot be undone."),this.deleteError&&i("p",{class:"text-danger"},"product-has-target-groups"===(null===(t=this.deleteError.data)||void 0===t?void 0:t.error)?"You need to delete all domains, load balancers and target groups inside the product before deleting it.":"Delete failed."),i("div",{slot:"actions"},i("dvn-button",{view:"flat",onClick:()=>{this.showDeleteConfirmation=!1,this.deleteError=void 0}},"Cancel"),i("dvn-button",{tint:"danger",onClick:this.onConfirmDeleteProduct},"Yes, Delete"))):null},this.onSubmitEditProductForm=t=>{const{values:i}=t.detail;this.apiDevingen.updateProduct(this.product._id,Object.assign(Object.assign({},this.product),{name:i.name})).then((()=>{this.showEditProductForm=!1,this.fetchProduct()})).catch((t=>this.updateError=t))},this.onConfirmDeleteProduct=()=>{this.apiDevingen.deleteProduct(this.product._id).then((()=>location.pathname="/")).catch((t=>this.deleteError=t))}}componentWillLoad(){this.fetchProduct()}render(){const{apiData:t,apiDevingen:e,apiKimlik:a,product:o,products:d,workspaceOwnerships:h}=this;if(!o)return i("div",{class:"d-flex justify-content-center pt-3"},i("dvn-progress",{indefinite:!0}));let p=`devingen-product-root-${o.type}`;return"damga"===o.type?i(s,null,this.renderHeader(),i("damga-home",{apiEndpoint:n.damga,apiHeaders:{Authorization:a.api.getDefaults().headers.Authorization},apiQueryParams:{productId:o._id},extraTabs:[{key:"dashboard",label:"Dashboard",render:()=>i("damga-dashboard",{apiDamga:new r(n.damga,{Authorization:a.api.getDefaults().headers.Authorization},{productId:o._id}),apiServicesDamga:new l(n.dasDamga,{Authorization:a.api.getDefaults().headers.Authorization},{productId:o._id})})}]}),this.renderEditProductForm(),this.renderDeleteProductConfirmation()):i(s,null,this.renderHeader(),this.renderEditProductForm(),this.renderDeleteProductConfirmation(),i(p,{apiData:t,apiDevingen:e,apiHeaders:{Authorization:a.api.getDefaults().headers.Authorization},product:o,products:d,workspaceOwnerships:h}))}};export{h as devingen_product_page}