import{getAddon as e}from"@clevercloud/client/esm/api/v2/providers.js";import{ONE_SECOND as o}from"@clevercloud/client/esm/with-cache.js";import{fakeString as n}from"./lib/fake-strings.js";import{sendToApi as r}from"./lib/send-to-api.js";import{defineSmartComponent as i}from"./lib/smart/define-smart-component.js";import"./cc-smart-container.js";import{CcAddonHeaderClient as t}from"./cc-addon-header.client.js";import"./cc-addon-header.js";i({selector:'cc-addon-header[smart-mode="elastic"]',params:{apiConfig:{type:Object},ownerId:{type:String},addonId:{type:String},logsUrlPattern:{type:String}},onContextUpdate({context:e,updateComponent:o,signal:r}){const{apiConfig:i,ownerId:t,addonId:d}=e,s=new a({apiConfig:i,ownerId:t,addonId:d,signal:r});let l="";o("state",{type:"loading",logsUrl:n(15),openLinks:[{url:n(15),name:n(5)},{url:n(15),name:n(5)}]}),s.getProviderWithZone().then((({rawAddon:n,rawProvider:r,zone:i})=>{l=e.logsUrlPattern.replace(":id",n.id);const t=[],a=r.services.find((e=>"apm"===e.name));if(a?.enabled&&null!=r.config.host){const e=`https://kibana-${r.config.host}/app/apm`;t.push({name:"APM",url:e})}const d=r.services.find((e=>"kibana"===e.name));if(d?.enabled&&null!=r.config.host){const e=`https://kibana-${r.config.host}/`;t.push({name:"KIBANA",url:e})}o("state",{type:"loaded",providerId:n.provider.name,providerLogoUrl:n.provider.logoUrl,name:n.name,id:n.realId,zone:i,logsUrl:l,openLinks:t})})).catch((e=>{console.error(e),o("state",{type:"error"})}))}});class a extends t{constructor({apiConfig:e,ownerId:o,addonId:n,signal:r}){super({apiConfig:e,ownerId:o,addonId:n,providerId:"es-addon",signal:r})}_getAddonProvider(){return e({providerId:this._provider,addonId:this._addonId}).then(r({apiConfig:this._apiConfig,signal:this._signal,cacheDelay:o}))}async getProviderWithZone(){const e=await this.getAddon(),[o,n]=await Promise.all([this._getAddonProvider(),this.getZone(e.region)]);return{rawAddon:e,rawProvider:o,zone:n}}}
//# sourceMappingURL=cc-addon-header.smart-elastic.js.map
