import{r as registerInstance,h,H as Host}from"./index-ecdfb761.js";import{p as prod}from"./services-63217112.js";import{S as SingleChoiceField}from"./index-23baeeef.js";import{D as DvnDataAdapter}from"./DvnDataAdapter-536a3258.js";import"./FieldGenerator-3ae403b2.js";import"./BaseField-0b01dc2c.js";var DevingenDataProviderProducts=function(){function t(t,e,r){if(r===void 0){r=""}this.devingenApi=t;this.workspaceId=e;this.productType=r}t.prototype.getInitialData=function(){return this.getData()};t.prototype.getData=function(){var t=this;var e=this,r=e.productType,n=e.workspaceId;return new Promise((function(e){t.devingenApi.getProducts({productType:r,workspaceId:n}).then((function(t){return e(t.results.sort((function(t,e){return t.name.localeCompare(e.name)})))}))}))};t.prototype.getQuickSearchText=function(){return""};t.prototype.isQuickSearchEnabled=function(){return false};t.prototype.setInitialData=function(t){};t.prototype.setQuickSearchText=function(t){};return t}();var DevingenProductRootKimlik=function(){function t(t){var e=this;registerInstance(this,t);this.renderSettingsForm=function(){if(!e.showSettingsForm){return null}return h("dvn-dialog",{shown:true,onDismiss:function(){return e.showSettingsForm=false},clip:false},h("doldurma-form",{fields:[new SingleChoiceField("databaseProduct","Database",[],"","select").setDataProvider(new DevingenDataProviderProducts(e.apiDevingen,e.product.workspace._id,"taban")).setDataAdapter(new DvnDataAdapter("name","_id")).require()],onSubmit:e.onSubmitEditSettingsForm,submitButtonLabel:"Save"}))};this.onSubmitEditSettingsForm=function(t){var r=t.detail.values;if(e.productSettings);else{e.apiDevingen.createProductSettingsKimlik(e.product._id,r.databaseProduct,"",{}).then((function(){e.fetchProductSettings();e.showSettingsForm=false})).catch((function(t){return e.error=t}))}}}t.prototype.componentWillLoad=function(){this.fetchProductSettings()};t.prototype.fetchProductSettings=function(){var t=this;this.apiDevingen.findProductSettingsKimlik(this.product._id).then((function(e){t.productSettings=e;t.fetchDatabaseProductSettings()})).catch((function(e){var r;if(((r=e===null||e===void 0?void 0:e.data)===null||r===void 0?void 0:r.error)==="product-setting-not-found-for-product"){t.showSettingsForm=true}else{t.error=e}}))};t.prototype.fetchDatabaseProductSettings=function(){var t=this;this.apiDevingen.findProductSettingsTaban(this.productSettings.databaseProduct._id).then((function(e){return t.databaseProductSettings=e})).catch((function(e){console.log(e);t.error=e}))};t.prototype.render=function(){var t=this,e=t.error,r=t.databaseProductSettings;if(e){return h(Host,null,h("div",{class:"d-flex justify-content-center"},h("devingen-error-card",{error:e,message:"Unexpected error occurred."})))}if(!r){return h(Host,{class:"d-flex justify-content-center"},h("dvn-progress",{indefinite:true}),this.renderSettingsForm())}return h(Host,{class:"d-flex flex-grow-1 flex-column"},h("kimlik-home",{apiEndpoint:"".concat(prod.kimlik,"/").concat(r.databaseName),apiHeaders:this.apiHeaders}),this.renderSettingsForm())};return t}();export{DevingenProductRootKimlik as devingen_product_root_kimlik};