import{create as e}from"@clevercloud/client/esm/api/v2/oauth-consumer.js";import{snakeCase as t}from"./lib/change-case.js";import{notifySuccess as o,notifyError as r}from"./lib/notifications.js";import{sendToApi as n}from"./lib/send-to-api.js";import{defineSmartComponent as c}from"./lib/smart/define-smart-component.js";import{i18n as s}from"./translation.js";import"./cc-smart-container.js";import{CcOauthConsumerWasCreatedEvent as a}from"./components/cc-oauth-consumer-form/cc-oauth-consumer-form.events.js";import"./cc-oauth-consumer-form.js";c({selector:"cc-oauth-consumer-form[smart-mode=create]",params:{apiConfig:{type:Object},ownerId:{type:String}},onContextUpdate({context:e,updateComponent:t,onEvent:n,component:c}){const{apiConfig:m,ownerId:p}=e,u=new i(m,p);t("state",{type:"idle-create"}),n("cc-oauth-consumer-create",(e=>{const n=e.name;t("state",(e=>{e.type="creating"})),u.createOauthConsumer(e).then((e=>{o(s("cc-oauth-consumer-form.create.success",{oauthConsumerName:n})),c.resetOauthConsumerForm(),t("state",{type:"idle-create"}),c.dispatchEvent(new a(e))})).catch((e=>{console.error(e),r(s("cc-oauth-consumer-form.create.error")),t("state",(e=>{e.type="idle-create"}))}))}))}});class i{constructor(e,t){this._apiConfig=e,this._ownerId=t}createOauthConsumer(o){const r=Object.fromEntries(Object.entries(o.rights).map((([e,o])=>[t(e),o]))),c={name:o.name,url:o.url,baseUrl:o.baseUrl,description:o.description,picture:o.picture,rights:r};return e({id:this._ownerId},c).then(n({apiConfig:this._apiConfig})).then((e=>e.key))}}
//# sourceMappingURL=cc-oauth-consumer-form.smart-create.js.map
