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 n}from"./p-0b1ac773.js";import{V as o}from"./p-ad6da9fe.js";import"./p-31e77e7b.js";import"./p-105f7627.js";import"./p-35c7f358.js";const a=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-dropdown",{placement:"rightTop",trigger:"click",leaned:!0},i("dvn-icon-button",{iconName:"uil uil-cog",scale:"small",view:"flat"}),i("div",{slot:"content"},i("dvn-menu",{leaned:!0,width:"200px"},i("dvn-menu-item",{onClick:()=>this.showEditProductForm=!0},"Settings"),["damga","sepet"].includes(this.product.type)&&i("stencil-route-link",{url:`/products/${this.product._id}/api-keys`},i("dvn-menu-item",null,"API Keys"))))))))},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 n).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:n,product:o,products:a,workspaceOwnerships:l}=this;if(!o)return i("div",{class:"d-flex justify-content-center pt-3"},i("dvn-progress",{indefinite:!0}));let r=`devingen-product-root-${o.type}`;return i(s,null,this.renderHeader(),this.renderEditProductForm(),this.renderDeleteProductConfirmation(),i(r,{apiData:t,apiKimlik:n,apiDevingen:e,apiHeaders:{Authorization:n.api.getDefaults().headers.Authorization,"devingen-product-id":this.product._id},product:o,products:a,workspaceOwnerships:l}))}};export{a as devingen_product_page}