import{k as v,l as U}from"./chunk-YKFXM3J7.js";import{a as d,b as O}from"./chunk-4ERZBM5I.js";import{D as R,E as P,n as m,o as L}from"./chunk-I7GW4F3B.js";import{cc as y,dc as I,qg as g,rg as V}from"./chunk-BPZQKZKD.js";import{J as p,Sa as C,be as j,g as n,h as a,ha as S,ka as h,na as b,r as u,ta as l,x as c,xa as i}from"./chunk-WL5U2YIT.js";import{e as f}from"./chunk-ADEKKGI2.js";var J,A=f(()=>{b();C();V();O();I();j();L();U();P();J=(()=>{let r=class r{constructor(t,e,o){this.storageService=t,this.repositoryService=e,this.currentUserService=o,this.GLOBAL_VAULT_ID="00000000-0000-0000-0000-000000910ba1",this.triggerSubject=new n,this.trigger$=this.triggerSubject.asObservable(),this.currentRepositorySubject=new a(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)}getCurrentRepository(){return this.currentRepositorySubject.pipe(S(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!==d.pamSystemVaultID&&(e.lastSharedVaultId=t),this.storageService.set(e)}}getLastSelectedRepository(t){let e=this.repositoryService.resolveVaultId(this.storageService.get().lastSelectedVaultId);return t.find(o=>o.id===e)}getDefaultOrFirstRepository(t){return t.find(e=>e.id===g.empty())||t[0]}getFallbackRepository(){return this.repositoryService.getCurrentUserRepositories(y.RepositoriesContentView).pipe(p(t=>t.length>0),c(t=>this.getLastSelectedRepository(t)||this.getDefaultOrFirstRepository(t)),h(t=>this.setCurrentRepository(t)))}emitTrigger(t){this.triggerSubject.next(t??"")}};r.\u0275fac=function(e){return new(e||r)(i(m),i(v),i(R))},r.\u0275prov=l({token:r,factory:r.\u0275fac,providedIn:"root"});let s=r;return s})()});export{J as a,A as b};
