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