import{k as m,l as L}from"./chunk-WNPXWF4E.js";import{a as R,b as V}from"./chunk-QQZCALHS.js";import{V as g,W as I,j as y,k as j}from"./chunk-INYFUTXB.js";import{Qf as l,Rf as C}from"./chunk-2GUKPKKM.js";import{J as c,Sd as b,g as o,h as n,ha as p,ka as S,na as v,oa as f,r as u,ta as h,x as a,ya as i}from"./chunk-XJKQ67XR.js";import{e as d}from"./chunk-SZAW6ZBW.js";var B,O=d(()=>{v();f();C();V();b();j();L();I();B=(()=>{class r{constructor(t,e,s){this.storageService=t,this.repositoryService=e,this.currentUserService=s,this.GLOBAL_VAULT_ID="00000000-0000-0000-0000-000000910ba1",this.triggerSubject=new o,this.trigger$=this.triggerSubject.asObservable(),this.currentRepositorySubject=new n(null)}get isCurrentRepoSystemRepo(){return this.getCurrentRepositoryIdSnapshot()===this.GLOBAL_VAULT_ID}getCurrentRepositorySnapshot(){return this.currentRepositorySubject.getValue()}getCurrentRepositoryIdSnapshot(){let t=this.getCurrentRepositorySnapshot();return t?t.id:""}isCurrentRepositoryPrivate(){let t=this.getCurrentRepositoryIdSnapshot();return this.repositoryService.isPrivateId(t)}isCurrentRepositoryGlobal(){let t=this.getCurrentRepositoryIdSnapshot();return this.repositoryService.isSystemVaultId(t)}isCurrentRepositoryPam(){return this.getCurrentRepositorySnapshot()?.isPamVault}isCurrentRepositoryPamSystemVault(){let t=this.getCurrentRepositoryIdSnapshot();return this.repositoryService.isPamSystemVaultId(t)}isVaultOwner(){return this.currentUserService.isVaultOwner(this.getCurrentRepositoryIdSnapshot())}getCurrentRepository(){return this.currentRepositorySubject.pipe(p(t=>t?u(t):this.getFallbackRepository()))}setCurrentRepository(t){!this.currentRepositorySubject.value&&!t||this.currentRepositorySubject.value&&t&&!["id","name","hasCustomImage","imageBytes","imageName"].some(e=>this.currentRepositorySubject.value[e]!==t[e])&&JSON.stringify(this.currentRepositorySubject.value.repositorySettings)===JSON.stringify(t.repositorySettings)||(t&&this.saveInStorage(t.id),this.currentRepositorySubject.next(t))}updateLockStatus(t){let e=this.currentRepositorySubject.getValue();e&&(e.isLocked=t,this.setCurrentRepository(e))}clearCurrentRepository(){this.currentRepositorySubject.next(null)}saveInStorage(t){if(t&&this.currentUserService.currentUserSnapshot){let e=this.storageService.get();e.lastSelectedVaultId=this.repositoryService.getVaultAlias(t),!this.repositoryService.isPrivateId(t)&&!this.repositoryService.isSystemVaultId(t)&&t!==R.pamSystemVaultID&&(e.lastSharedVaultId=t),this.storageService.set(e)}}getLastSelectedRepository(t){let e=this.repositoryService.resolveVaultId(this.storageService.get().lastSelectedVaultId);return t.find(s=>s.id===e)}getDefaultOrFirstRepository(t){return t.find(e=>e.id===l.empty())||t[0]}getFallbackRepository(){return this.repositoryService.userRepositories.pipe(c(t=>t.length>0),a(t=>this.getLastSelectedRepository(t)||this.getDefaultOrFirstRepository(t)),S(t=>this.setCurrentRepository(t)))}emitTrigger(t){this.triggerSubject.next(t??"")}static{this.\u0275fac=function(e){return new(e||r)(i(y),i(m),i(g))}}static{this.\u0275prov=h({token:r,factory:r.\u0275fac,providedIn:"root"})}}return r})()});export{B as a,O as b};
