import{getDocUrl as e}from"./lib/dev-hub-url.js";import{fakeString as a}from"./lib/fake-strings.js";import{notifySuccess as t,notifyError as n}from"./lib/notifications.js";import{defineSmartComponent as d}from"./lib/smart/define-smart-component.js";import{i18n as o}from"./translation.js";import"./cc-smart-container.js";import{CcAddonCredentialsBetaClient as s}from"./cc-addon-credentials-beta.client.js";import"./cc-addon-credentials-beta.js";const i={type:"loading",tabs:{admin:{content:[{code:"user",value:a(10)},{code:"password",value:a(10)},{code:"ng",kind:"standard",value:{status:"disabled"}}],docLink:{text:o("cc-addon-credentials-beta.doc-link.otoroshi-ng"),href:e("/addons/otoroshi/#use-otoroshi-in-a-network-group")}},api:{content:[{code:"api-client-user",value:a(10)},{code:"api-client-secret",value:a(10)},{code:"api-url",value:a(10)},{code:"open-api-url",value:a(10)},{code:"ng",kind:"standard",value:{status:"disabled"}}],docLink:{text:o("cc-addon-credentials-beta.doc-link.otoroshi-api"),href:e("/addons/otoroshi/#manage-otoroshi-from-its-api")}}}};function r(e){return null==e?{status:"disabled"}:{status:"enabled",id:e.id}}d({selector:'cc-addon-credentials-beta[smart-mode="otoroshi"]',params:{apiConfig:{type:Object},addonId:{type:String},ownerId:{type:String}},onContextUpdate({context:e,onEvent:a,updateComponent:d,signal:s}){const{apiConfig:r,addonId:l,ownerId:u}=e,p=new c({apiConfig:r,ownerId:u,addonId:l,signal:s});function g(e){d("state",(a=>{a.tabs=Object.fromEntries(Object.entries(a.tabs).map((([a,t])=>[a,{...t,content:t.content.map((a=>"ng"===a.code?"function"==typeof e?e(a):e:a))}])))}))}d("state",i),p.getAllCredentials().then((e=>{d("state",(a=>{a.type="loaded",a.tabs=Object.fromEntries(Object.entries(a.tabs).map((([a,t])=>[a,{...t,content:e[a]}])))}))})).catch((e=>{console.error(e),d("state",{type:"error"})})),a("cc-ng-enable",(()=>{g({code:"ng",kind:"standard",value:{status:"enabling"}}),p.createNg().then((e=>{g({code:"ng",kind:"standard",value:{status:"enabled",id:e.features.networkGroup.id}}),t(o("cc-addon-credentials-beta.ng-standard.enabling.success"))})).catch((e=>{console.error(e),g({code:"ng",kind:"standard",value:{status:"disabled"}}),n(o("cc-addon-credentials-beta.ng-standard.enabling.error"))}))})),a("cc-ng-disable",(()=>{g((e=>({code:"ng",kind:"standard",value:{id:e.value.id,status:"disabling"}}))),p.deleteNg().then((()=>{g({code:"ng",kind:"standard",value:{status:"disabled"}}),t(o("cc-addon-credentials-beta.ng-standard.disabling.success"))})).catch((e=>{console.error(e),g((e=>({code:"ng",kind:"standard",value:{id:e.value.id,status:"enabled"}}))),n(o("cc-addon-credentials-beta.ng-standard.disabling.error"))}))}))}});class c extends s{constructor({apiConfig:e,ownerId:a,addonId:t,signal:n}){super({apiConfig:e,ownerId:a,addonId:t,providerId:"otoroshi",signal:n})}async getCredentials(e){const a=await this.getAddonWithOperator();return"api"===e?[{code:"api-client-user",value:a.api.user},{code:"api-client-secret",value:a.api.secret},{code:"api-url",value:a.api.url},{code:"open-api-url",value:a.api.openapi},{code:"ng",kind:"standard",value:r(a.features.networkGroup)}]:[{code:"user",value:a.initialCredentials.user},{code:"password",value:a.initialCredentials.password},{code:"ng",kind:"standard",value:r(a.features.networkGroup)}]}async getAllCredentials(){const[e,a]=await Promise.all([this.getCredentials("admin"),this.getCredentials("api")]);return{admin:e,api:a}}}
//# sourceMappingURL=cc-addon-credentials-beta.smart-otoroshi.js.map
