import{getAddon as e}from"@clevercloud/client/esm/api/v2/providers.js";import{ONE_SECOND as a}from"@clevercloud/client/esm/with-cache.js";import{getDocUrl as t}from"./lib/dev-hub-url.js";import{sendToApi as n}from"./lib/send-to-api.js";import{defineSmartComponent as o}from"./lib/smart/define-smart-component.js";import{i18n as s}from"./translation.js";import"./cc-smart-container.js";import{CcAddonCredentialsBetaClient as i}from"./cc-addon-credentials-beta.client.js";import"./cc-addon-credentials-beta.js";const d={type:"loading",tabs:{elastic:{content:[{code:"host",value:"fake-skeleton"},{code:"user",value:"fake-skeleton"},{code:"password",value:"fake-skeleton"}],docLink:{text:s("cc-addon-credentials-beta.doc-link.elastic"),href:t("/addons/elastic")}},kibana:{content:[{code:"user",value:"fake-skeleton"},{code:"password",value:"fake-skeleton"}],docLink:{text:s("cc-addon-credentials-beta.doc-link.elastic-kibana"),href:t("/addons/elastic/#kibana")}},apm:{content:[{code:"user",value:"fake-skeleton"},{code:"password",value:"fake-skeleton"},{code:"token",value:"fake-skeleton"}],docLink:{text:s("cc-addon-credentials-beta.doc-link.elastic-apm"),href:t("/addons/elastic/#elastic-apm")}}}};o({selector:'cc-addon-credentials-beta[smart-mode="elastic"]',params:{apiConfig:{type:Object},addonId:{type:String},ownerId:{type:String}},onContextUpdate({context:e,updateComponent:a,signal:t}){const{apiConfig:n,addonId:o,ownerId:s}=e,i=new c({apiConfig:n,ownerId:s,addonId:o,signal:t});a("state",d),i.getAllCredentials().then((({elastic:e,kibana:t,apm:n})=>{a("state",(a=>{a.type="loaded";const o={elastic:{...a.tabs.elastic,content:e}};null!=t&&(o.kibana={...a.tabs.kibana,content:t}),null!=n&&(o.apm={...a.tabs.apm,content:n}),a.tabs=o}))})).catch((e=>{console.error(e),a("state",{type:"error"})}))}});class c extends i{constructor({apiConfig:e,ownerId:a,addonId:t,signal:n}){super({apiConfig:e,ownerId:a,addonId:t,providerId:"es-addon",signal:n})}_getAddonProvider(t){return e({providerId:t,addonId:this._addonId}).then(n({apiConfig:this._apiConfig,signal:this._signal,cacheDelay:a}))}async getCredentials(e){const a=await this._getAddonProvider(this._providerId);switch(e){case"elastic":return[{code:"host",value:a.config.host},{code:"user",value:a.config.user},{code:"password",value:a.config.password}];case"kibana":return[{code:"user",value:a.config.kibana_user},{code:"password",value:a.config.kibana_password}];case"apm":return[{code:"user",value:a.config.apm_user},{code:"password",value:a.config.apm_password},{code:"token",value:a.config.apm_auth_token}]}}async getAllCredentials(){const e=await this._getAddonProvider(this._providerId),a=e.services.find((e=>"kibana"===e.name)),t=e.services.find((e=>"apm"===e.name)),n=a?.enabled??!1,o=t?.enabled??!1,[s,i,d]=await Promise.all([this.getCredentials("elastic"),n?this.getCredentials("kibana"):null,o?this.getCredentials("apm"):null]);return{elastic:s,kibana:i,apm:d}}}
//# sourceMappingURL=cc-addon-credentials-beta.smart-elastic.js.map
