import{get as e,getSecret as t}from"@clevercloud/client/esm/api/v2/oauth-consumer.js";import{camelCase as s}from"./lib/change-case.js";import{sendToApi as r}from"./lib/send-to-api.js";import{defineSmartComponent as n}from"./lib/smart/define-smart-component.js";import"./cc-smart-container.js";import"./cc-oauth-consumer-info.js";const i={almighty:!1,accessOrganisations:!1,accessOrganisationsBills:!1,accessOrganisationsConsumptionStatistics:!1,accessOrganisationsCreditCount:!1,accessPersonalInformation:!1,manageOrganisations:!1,manageOrganisationsApplications:!1,manageOrganisationsMembers:!1,manageOrganisationsServices:!1,managePersonalInformation:!1,manageSshKeys:!1};n({selector:"cc-oauth-consumer-info",params:{apiConfig:{type:Object},ownerId:{type:String},key:{type:String}},onContextUpdate({context:e,updateComponent:t}){const{apiConfig:r,ownerId:n,key:o}=e,c=new a(r,n,o);t("state",{type:"loading"}),c.getOauthConsumerWithSecret().then((({rawOauthConsumer:e,secret:r,errors:n})=>{if(null!=e){const n=Object.fromEntries(Object.entries(e.rights).map((([e,t])=>[s(e),t]))),a={...i,...n};t("state",{type:"loaded",name:e.name,url:e.url,baseUrl:e.baseUrl,description:e.description,picture:e.picture,rights:a,key:e.key,secret:r})}else null==e&&(n.forEach((e=>{console.error(e)})),t("state",{type:"error"}))}))}});class a{constructor(e,t,s){this._apiConfig=e,this._ownerId=t,this._key=s}getOauthConsumer(){return e({id:this._ownerId,key:this._key}).then(r({apiConfig:this._apiConfig}))}getSecret(){return t({id:this._ownerId,key:this._key}).then(r({apiConfig:this._apiConfig}))}getOauthConsumerWithSecret(){return Promise.allSettled([this.getOauthConsumer(),this.getSecret()]).then((e=>{const[t,s]=e;return{rawOauthConsumer:"fulfilled"===t.status?t.value:null,secret:"fulfilled"===s.status?s.value.secret:null,errors:e.filter((e=>"rejected"===e.status))}}))}}
//# sourceMappingURL=cc-oauth-consumer-info.smart.js.map
