import{r as t,h as s,H as e}from"./p-9f21f85f.js";import{p as i}from"./p-d1fe7ec4.js";import{S as r}from"./p-1187cc7c.js";import{D as o}from"./p-d93d87fd.js";import"./p-31e77e7b.js";import"./p-105f7627.js";class n{constructor(t,s,e=""){this.devingenApi=t,this.workspaceId=s,this.productType=e}getInitialData(){return this.getData()}getData(){const{productType:t,workspaceId:s}=this;return new Promise((e=>{this.devingenApi.getProducts({productType:t,workspaceId:s}).then((t=>e(t.results.sort(((t,s)=>t.name.localeCompare(s.name))))))}))}getQuickSearchText(){return""}isQuickSearchEnabled(){return!1}setInitialData(t){}setQuickSearchText(t){}}const a=class{constructor(e){t(this,e),this.renderSettingsForm=()=>this.showSettingsForm?s("dvn-dialog",{shown:!0,onDismiss:()=>this.showSettingsForm=!1,clip:!1},s("doldurma-form",{fields:[new r("databaseProduct","Database",[],"","select").setDataProvider(new n(this.apiDevingen,this.product.workspace._id,"taban")).setDataAdapter(new o("name","_id")).require()],onSubmit:this.onSubmitEditSettingsForm,submitButtonLabel:"Save"})):null,this.onSubmitEditSettingsForm=t=>{const{values:s}=t.detail;this.productSettings||this.apiDevingen.createProductSettingsKimlik(this.product._id,s.databaseProduct,"",{}).then((()=>{this.fetchProductSettings(),this.showSettingsForm=!1})).catch((t=>this.error=t))}}componentWillLoad(){this.fetchProductSettings()}fetchProductSettings(){this.apiDevingen.findProductSettingsKimlik(this.product._id).then((t=>{this.productSettings=t,this.fetchDatabaseProductSettings()})).catch((t=>{var s;console.log("ahoy",t),"product-setting-not-found-for-product"===(null===(s=null==t?void 0:t.data)||void 0===s?void 0:s.error)?(console.log(1),this.showSettingsForm=!0):this.error=t}))}fetchDatabaseProductSettings(){this.apiDevingen.findProductSettingsTaban(this.productSettings.databaseProduct._id).then((t=>this.databaseProductSettings=t)).catch((t=>{console.log(t),this.error=t}))}render(){const{error:t,databaseProductSettings:r}=this;return t?s(e,null,s("div",{class:"d-flex justify-content-center"},s("devingen-error-card",{error:t,message:"Unexpected error occurred."}))):r?s(e,{class:"d-flex flex-grow-1 flex-column"},s("kimlik-home",{apiEndpoint:`${i.kimlik}/${r.databaseName}`,apiHeaders:this.apiHeaders}),this.renderSettingsForm()):s(e,{class:"d-flex justify-content-center"},s("dvn-progress",{indefinite:!0}),this.renderSettingsForm())}};export{a as devingen_product_root_kimlik}