import{getAllEnvVarsForAddons as e,get as n}from"@clevercloud/client/esm/api/v2/application.js";import{sendToApi as a}from"./lib/send-to-api.js";import{defineSmartComponent as t}from"./lib/smart/define-smart-component.js";import"./cc-smart-container.js";import"./cc-env-var-linked-services.js";t({selector:'cc-env-var-linked-services[type="addon"]',params:{apiConfig:{type:Object},ownerId:{type:String},appId:{type:String}},onContextUpdate({context:e,updateComponent:n,signal:a}){const{apiConfig:t,ownerId:p,appId:o}=e;n("state",{type:"loading",name:""});const s=new i(t,a);s.fetchAppName({ownerId:p,appId:o}).then((e=>{n("appName",e)})),s.fetchEnvVarLinkedAddons({ownerId:p,appId:o}).then((e=>{n("state",{type:"loaded",services:e})})).catch((e=>{console.error(e),n("state",{type:"error"})}))}});class i{constructor(e,n){this.apiConfig=e,this.signal=n}async fetchEnvVarLinkedAddons({ownerId:n,appId:t}){return(await e({id:n,appId:t}).then(a({apiConfig:this.apiConfig,signal:this.signal}))).map((e=>({id:e.addon_id,name:e.addon_name,variables:e.env})))}async fetchAppName({ownerId:e,appId:t}){return(await n({id:e,appId:t}).then(a({apiConfig:this.apiConfig,signal:this.signal}))).name}}
//# sourceMappingURL=cc-env-var-linked-services.smart-addon.js.map
