import{ONE_SECOND as e}from"@clevercloud/client/esm/with-cache.js";import{getDocUrl as t}from"./lib/dev-hub-url.js";import{sendToApi as o}from"./lib/send-to-api.js";import{defineSmartComponent as r}from"./lib/smart/define-smart-component.js";import{i18n as a}from"./translation.js";import"./cc-smart-container.js";import{CcAddonCredentialsBetaClient as n}from"./cc-addon-credentials-beta.client.js";import"./cc-addon-credentials-beta.js";const d={type:"loading",tabs:{default:{content:[{code:"url",value:"fake-skeleton"},{code:"token",value:"fake-skeleton"},{code:"tenant-namespace",value:"fake-skeleton"}],docLink:{text:a("cc-addon-credentials-beta.doc-link.pulsar"),href:t("/addons/pulsar")}}}},s="addon-pulsar";r({selector:'cc-addon-credentials-beta[smart-mode="pulsar"]',params:{apiConfig:{type:Object},addonId:{type:String},ownerId:{type:String}},onContextUpdate({context:e,updateComponent:t,signal:o}){const{apiConfig:r,addonId:a,ownerId:n}=e,s=new i({apiConfig:r,ownerId:n,addonId:a,signal:o});t("state",d),s.getCredentials().then((e=>{t("state",(t=>{t.type="loaded",t.tabs.default.content=e}))})).catch((e=>{console.error(e),t("state",{type:"error"})}))}});class i extends n{constructor({apiConfig:e,ownerId:t,addonId:o,signal:r}){super({apiConfig:e,ownerId:t,addonId:o,providerId:s,signal:r})}_getAddonProvider(t){return l({providerId:this._providerId,addonId:t}).then(o({apiConfig:this._apiConfig,signal:this._signal,cacheDelay:e}))}_getCluster(t){return c({providerId:s,clusterId:t}).then(o({apiConfig:this._apiConfig,signal:this._signal,cacheDelay:e}))}async getCredentials(){const e=await this._getAddon(),t=e.realId,o=await this._getAddonProvider(t),r=await this._getCluster(o.cluster_id);let a;if(null!=r.pulsar_tls_port)a=`pulsar+ssl://${r.url}:${r.pulsar_tls_port}`;else{if(null==r.pulsar_port)throw new Error("Missing TLS port and default port");a=`pulsar+ssl://${r.url}:${r.pulsar_port}`}return[{code:"url",value:a},{code:"token",value:o.token},{code:"tenant-namespace",value:`${o.tenant}/${e.realId}`}]}}function l(e){return Promise.resolve({method:"get",url:`/v4/addon-providers/${e.providerId}/addons/${e.addonId}`,headers:{Accept:"application/json"}})}function c(e){return Promise.resolve({method:"get",url:`/v4/addon-providers/${e.providerId}/clusters/${e.clusterId}`,headers:{Accept:"application/json"}})}export{l as getAddonProvider,c as getCluster};
//# sourceMappingURL=cc-addon-credentials-beta.smart-pulsar.js.map
