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