import{get as n}from"@clevercloud/client/esm/api/v2/addon.js";import{defineSmartComponent as o}from"./lib/define-smart-component.js";import{notifySuccess as e,notifyError as a}from"./lib/notifications.js";import{sendToApi as t}from"./lib/send-to-api.js";import{i18n as r}from"./translation.js";import"./cc-smart-container.js";import"./cc-env-var-form.js";function i({realAddonId:n}){return Promise.resolve({method:"get",url:`/v4/addon-providers/config-provider/addons/${n}/env`,headers:{Accept:"application/json"}})}function d({realAddonId:n},o){return Promise.resolve({method:"put",url:`/v4/addon-providers/config-provider/addons/${n}/env`,headers:{Accept:"application/json","Content-Type":"application/json"},body:o})}o({selector:'cc-env-var-form[context="config-provider"]',params:{apiConfig:{type:Object},ownerId:{type:String},addonId:{type:String}},onContextUpdate({context:o,onEvent:s,updateComponent:p,signal:c}){p("state",{type:"loading"});const{apiConfig:l,ownerId:f,addonId:m}=o;let v=null;(function({apiConfig:o,signal:e,ownerId:a,addonId:r}){return n({id:a,addonId:r}).then(t({apiConfig:o,signal:e}))})({apiConfig:l,ownerId:f,addonId:m,signal:c}).then((n=>(p("addonName",n.name),v=n.realId,async function({apiConfig:n,signal:o,realAddonId:e}){return i({realAddonId:e}).then(t({apiConfig:n,signal:o}))}({apiConfig:l,realAddonId:v,signal:c})))).then((n=>{p("state",{type:"loaded",validationMode:"simple",variables:n})})).catch((n=>{console.error(n),p("state",{type:"error"})})),s("cc-env-var-form:submit",(n=>{p("state",(n=>{n.type="saving"})),async function({apiConfig:n,realAddonId:o,variables:e}){return d({realAddonId:o},e).then(t({apiConfig:n}))}({apiConfig:l,realAddonId:v,variables:n}).then((()=>{p("state",(o=>{o.variables=n})),e(r("cc-env-var-form.update.success"))})).catch((()=>a(r("cc-env-var-form.update.error")))).finally((()=>{p("state",(n=>{n.type="loaded"}))}))}))}});export{i as getConfigProviderEnv,d as updateConfigProviderEnv};
//# sourceMappingURL=cc-env-var-form.smart-config-provider.js.map
