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