import{g as v,h as L}from"./chunk-TIIPYMHO.js";import{a as R,b as V}from"./chunk-QQZCALHS.js";import{P as y,Q as I,h as l,i as j}from"./chunk-DCSOZT4N.js";import{Kb as g,Lb as C}from"./chunk-5XZEGBWY.js";import{Gd as b,J as c,g as o,h as n,ha as p,ka as S,ma as m,na as f,r as u,sa as h,x as a,xa as i}from"./chunk-JSJB5BKT.js";import{e as d}from"./chunk-SZAW6ZBW.js";var B,O=d(()=>{m();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}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===g.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(l),i(v),i(y))}}static{this.\u0275prov=h({token:r,factory:r.\u0275fac,providedIn:"root"})}}return r})()});export{B as a,O as b};
