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