{ "version": 3, "sources": ["src/app/services/account-context.ts"], "sourcesContent": ["import { Injectable, OnDestroy, OnInit, PLATFORM_ID, computed, effect, inject, signal, untracked } from '@angular/core'\nimport { BehaviorSubject, Subject } from 'rxjs'\nimport { ApiService } from '../api/api.client'\nimport { IPatientProfile } from '../api/api.models'\nimport { map, tap } from 'rxjs/operators'\nimport { isPlatformBrowser } from '@angular/common'\n\n@Injectable({\n providedIn: 'root',\n})\nexport class AccountContext implements OnDestroy, OnInit {\n private platform = inject(PLATFORM_ID)\n\n public me$ = new BehaviorSubject(null)\n\n public me = signal(null)\n\n public countOfPlanned = signal(null)\n\n public isAuthorized = computed(() => {\n return !!this.me()\n })\n\n public telegramIsConfigured = signal(false)\n\n public telegramConnected = computed(() => {\n return (!!this.me()?.telegramBotId || this.telegramIsConfigured()) && this.isAuthorized()\n })\n\n constructor(private client: ApiService) {\n effect(() => {\n const profile = this.me()\n if (!profile) {\n return\n }\n untracked(() => {\n this.loadCountOfPlanned()\n })\n })\n this.ngOnInit()\n }\n\n public loadCountOfPlanned() {\n if (isPlatformBrowser(this.platform)) {\n this.client.countOfPlanned().subscribe((x) => {\n this.countOfPlanned.set(x)\n })\n }\n }\n\n public logoff() {\n return this.client.logoff().pipe(\n map((_) => {\n this.me.set(null)\n this.countOfPlanned.set(null)\n this.me$.next(null)\n })\n )\n }\n\n public configureTelegram() {\n this.telegramIsConfigured.set(true)\n }\n\n public relogin() {\n this.client.relogin().subscribe((x) => {\n this.load()\n })\n }\n\n public get() {\n return this.client.me().pipe(\n tap(\n (x) => {\n this.me.set(x)\n this.me$.next(x)\n },\n (error) => {\n this.me.set(null)\n this.countOfPlanned.set(null)\n this.me$.next(null)\n }\n )\n )\n }\n\n public load() {\n this.get().subscribe(() => {})\n }\n\n ngOnInit(): void {}\n\n ngOnDestroy(): void {}\n}\n"], "mappings": "qKAUA,IAAaA,GAAc,IAAA,CAArB,IAAOA,EAAP,MAAOA,CAAc,CAmBvBC,YAAoBC,EAAkB,CAA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ACN,KAAK3B,GAAGgB,IAAI,IAAI,EAChB,KAAKd,eAAec,IAAI,IAAI,EAC5B,KAAKlB,IAAIuB,KAAK,IAAI,CACtB,CAAC,CACJ,CAET,CAEOG,MAAI,CACP,KAAKC,IAAG,EAAGX,UAAU,IAAK,CAAE,CAAC,CACjC,CAEAF,UAAQ,CAAU,CAElBgB,aAAW,CAAU,yCAlFZpC,GAAcqC,EAAAC,CAAA,CAAA,CAAA,wBAAdtC,EAAcuC,QAAdvC,EAAcwC,UAAAC,WAFX,MAAM,CAAA,EAEhB,IAAOzC,EAAP0C,SAAO1C,CAAc,GAAA", "names": ["AccountContext", "constructor", "client", "platform", "inject", "PLATFORM_ID", "me$", "BehaviorSubject", "me", "signal", "countOfPlanned", "isAuthorized", "computed", "telegramIsConfigured", "telegramConnected", "_a", "telegramBotId", "effect", "untracked", "loadCountOfPlanned", "ngOnInit", "isPlatformBrowser", "subscribe", "x", "set", "logoff", "pipe", "map", "_", "next", "configureTelegram", "relogin", "load", "get", "tap", "error", "ngOnDestroy", "\u0275\u0275inject", "ApiService", "factory", "\u0275fac", "providedIn", "_AccountContext"] }