1import{i as T}from"./chunk-KGVH7VIN.js";import{b as f}from"./chunk-DSIDUYXM.js";import{a as E}from"./chunk-DA6X5B4D.js";import{e as U,i as D,j as d}from"./chunk-YPIHMCBJ.js";import{Ec as u,T as h,Y as i,a as y,b as g,f as o,kc as v,na as c,oa as S,v as a}from"./chunk-FEHQSQD2.js";var R=3600*1e3,A="__prefs_loaded_at",b=D,w=(()=>{class s{constructor(){this.http=i(u),this.env=i(f),this.auth=i(T),this.storage=i(d),this.consent=i(U),this.dirty=new Map,this.syncTimer=null,this._restored=c(0),this.restored=this._restored.asReadonly(),this.storage.registerSyncHook((t,e)=>{let r=this.auth.user()?.id;!r||!b.has(t)||(this.syncOwnerUid!==r&&this.discardQueue(r),this.dirty.set(t,e),this.scheduleSync())})}get(t,e=null){return this.storage.get(t)??e}set(t,e){this.storage.set(t,e)}load(t=!1){return o(this,null,function*(){let e=this.auth.user()?.id;if(e){if(!t){let r=Number(this.storage.get(A)??"0");if(r&&Date.now()-r<R)return}try{let r=yield a(this.http.get(`${this.env.api.apiUrl}/users/me/preferences`));if(this.auth.user()?.id!==e)return;for(let[n,l]of Object.entries(r))this.storage.set(n,l);this.storage.set(A,String(Date.now())),this._restored.update(n=>n+1)}catch(r){}}})}functionalGranted(){return this.consent.decided()&&this.consent.functional()}uploadLocal(){return o(this,null,function*(){let t=this.auth.user()?.id;if(!t||!this.functionalGranted())return;let e={};for(let r of b){let n=this.storage.get(r);n!=null&&(e[r]=n)}if(Object.keys(e).length&&this.auth.user()?.id===t)try{yield a(this.http.put(`${this.env.api.apiUrl}/users/me/preferences`,e))}catch(r){}})}scheduleSync(){this.syncTimer||(this.syncTimer=setTimeout(()=>{this.syncTimer=null,this.flush()},2e3))}discardQueue(t){this.dirty.clear(),this.syncOwnerUid=t}flush(){return o(this,null,function*(){if(!this.dirty.size||!this.auth.user())return;if(this.auth.user()?.id!==this.syncOwnerUid){this.discardQueue();return}if(!this.functionalGranted()){this.discardQueue();return}let t={};for(let[e,r]of this.dirty)t[e]=r;this.discardQueue();try{yield a(this.http.put(`${this.env.api.apiUrl}/users/me/preferences`,t))}catch(e){}})}static{this.\u0275fac=function(e){return new(e||s)}}static{this.\u0275prov=h({token:s,factory:s.\u0275fac,providedIn:"root"})}}return s})();var J=(()=>{class s{static{this.STORAGE_KEY="currency"}static{this.SUPPORTED=["USD","RUB","AMD"]}static{this.DEFAULT="USD"}constructor(){this.http=i(u),this.env=i(f),this.storage=i(d),this.ts=i(E),this.prefs=i(w),this.rates=c({USD:1}),this.updatedAt=c(null),this.currency=c(this.readStored()),this.formatter=v(()=>{let t=this.currency(),e=this.rates()[t]??1,r=this.localeFor(this.ts.lang()),n=t==="USD"?2:0,l=t!=="USD";return m=>{let p=(Number.isFinite(m)?m:0)*e,F=l?Math.ceil(p):p;try{return new Intl.NumberFormat(r,{style:"currency",currency:t,minimumFractionDigits:0,maximumFractionDigits:n}).format(F)}catch(N){return`$${m}`}}}),this.loadRates(),S(()=>{this.prefs.restored(),this.currency.set(this.readStored())})}readStored(){let t=this.storage.get(s.STORAGE_KEY);return t&&s.SUPPORTED.includes(t)?t:s.DEFAULT}setCurrency(t){!s.SUPPORTED.includes(t)||t===this.currency()||(this.currency.set(t),this.storage.set(s.STORAGE_KEY,t))}loadRates(){return o(this,null,function*(){try{let t=yield a(this.http.get(`${this.env.api.apiUrl}/currency/rates`)),e=t?.rates??{};this.rates.set(g(y({},e),{USD:1})),this.updatedAt.set(t?.updatedAt??null)}catch(t){this.rates.set({USD:1}),this.updatedAt.set(null)}})}format(t){return this.formatter()(t)}localeFor(t){switch(t){case"ru":return"ru-RU";case"hy":return"hy-AM";default:return"en-US"}}static{this.\u0275fac=function(e){return new(e||s)}}static{this.\u0275prov=h({token:s,factory:s.\u0275fac,providedIn:"root"})}}return s})();export{w as a,J as b};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.