import{getAllExposedEnvVars as e,updateAllExposedEnvVars as a}from"@clevercloud/client/esm/api/v2/application.js";import{toNameValueObject as t}from"@clevercloud/client/esm/utils/env-vars.js";import{fetchApp as n}from"./lib/api-helpers.js";import{notifySuccess as i,notifyError as o}from"./lib/notifications.js";import{sendToApi as r}from"./lib/send-to-api.js";import{defineSmartComponent as p}from"./lib/smart/define-smart-component.js";import{i18n as s}from"./translation.js";import"./cc-smart-container.js";import"./cc-env-var-form.js";function c({apiConfig:a,signal:t,ownerId:n,appId:i}){return e({id:n,appId:i}).then(r({apiConfig:a,signal:t})).then((e=>Object.entries(e).map((([e,a])=>({name:e,value:a})))))}p({selector:'cc-env-var-form[context="exposed-config"]',params:{apiConfig:{type:Object},ownerId:{type:String},appId:{type:String}},onContextUpdate({context:e,onEvent:p,updateComponent:l,signal:m}){const{apiConfig:d,ownerId:f,appId:v}=e;l("state",{type:"loading"}),l("resourceId",v),Promise.all([n({apiConfig:d,signal:m,ownerId:f,appId:v}),c({apiConfig:d,signal:m,ownerId:f,appId:v})]).then((([e,a])=>{l("appName",e.name),l("state",{type:"loaded",validationMode:"simple",variables:a})})).catch((e=>{console.error(e),l("state",{type:"error"})})),p("cc-env-var-form-submit",(e=>{l("state",(e=>{e.type="saving"})),function({apiConfig:e,signal:n,ownerId:i,appId:o,variables:p}){const s=t(p);return a({id:i,appId:o},s).then(r({apiConfig:e,signal:n}))}({apiConfig:d,ownerId:f,appId:v,variables:e,signal:m}).then((()=>{l("state",(a=>{a.variables=e})),i(s("cc-env-var-form.update.success"))})).catch((()=>o(s("cc-env-var-form.update.error")))).finally((()=>{l("state",(e=>{e.type="loaded"}))}))}))}});
//# sourceMappingURL=cc-env-var-form.smart-exposed-config.js.map
