import{notifySuccess as e,notifyError as t}from"./lib/notifications.js";import{sendToAuthBridge as o}from"./lib/send-to-auth-bridge.js";import{defineSmartComponent as n}from"./lib/smart/define-smart-component.js";import{i18n as a}from"./translation.js";import"./cc-smart-container.js";import{CcTokenWasUpdatedEvent as i}from"./components/cc-token-api-update-form/cc-token-api-update-form.events.js";import"./cc-token-api-update-form.js";n({selector:"cc-token-api-update-form",params:{apiConfig:{type:Object},apiTokenId:{type:String}},onContextUpdate({context:o,component:n,onEvent:p,updateComponent:s}){const{apiConfig:c,apiTokenId:d}=o,m=new r(c,d);s("state",{type:"loading"}),m.getToken().then((({name:e,description:t})=>{s("state",{type:"loaded",values:{name:e,description:t}})})).catch((e=>{console.error(e),s("state",{type:"error"})})),p("cc-token-change",(({name:o,description:r})=>{s("state",(e=>{e.type="updating"})),m.updateToken({name:o,description:r}).then((()=>{s("state",(e=>{e.type="loaded"})),n.dispatchEvent(new i(d)),e(a("cc-token-api-update-form.update-token.success"))})).catch((e=>{console.error(e),s("state",(e=>{e.type="loaded"})),t(a("cc-token-api-update-form.update-token.error"))}))}))}});class r{constructor(e,t){this._authBridgeConfig=e,this._tokenId=t}_getOneToken(e){return Promise.resolve({method:"get",url:`/api-tokens/${e.tokenId}`,headers:{Accept:"application/json"}})}_updateOneToken(e,t){return Promise.resolve({method:"put",url:`/api-tokens/${e.tokenId}`,headers:{Accept:"application/json","Content-Type":"application/json"},body:t})}getToken(){return this._getOneToken({tokenId:this._tokenId}).then(o({authBridgeConfig:this._authBridgeConfig}))}updateToken(e){return this._updateOneToken({tokenId:this._tokenId},e).then(o({authBridgeConfig:this._authBridgeConfig}))}}
//# sourceMappingURL=cc-token-api-update-form.smart.js.map
