{"version":3,"file":"chunk-fmqtucrs.js","sources":["packages/vanilla/lib/shared/dark-mode/src/dark-mode.service.ts"],"sourcesContent":["import { Injectable } from '@angular/core';\n\nimport { CookieName, CookieService, PERMANENT_COOKIE_EXPIRATION, WindowRef } from '@frontend/vanilla/core';\n\nconst DisabledCookieValue: string = '0';\nconst EnabledCookieValueOldDesktop: string = '1';\nconst EnabledCookieValue: string = '2';\n\n/**\n * @whatItDoes Allows toggling of dark mode and check if feature is enabled.\n *\n * @stable\n */\n@Injectable({\n providedIn: 'root',\n})\nexport class DarkModeService {\n private _isEnabled = this.getIsEnabled();\n\n get isEnabled(): boolean {\n return this._isEnabled;\n }\n\n constructor(\n private cookieService: CookieService,\n private windowRef: WindowRef,\n ) {}\n\n toggle() {\n this.writeCookie(this._isEnabled ? DisabledCookieValue : EnabledCookieValue);\n this._isEnabled = this.getIsEnabled();\n this.windowRef.nativeWindow.location.reload();\n }\n\n private writeCookie(value: string) {\n this.cookieService.putRaw(CookieName.DarkMode, value, { expires: PERMANENT_COOKIE_EXPIRATION });\n }\n\n private getIsEnabled(): boolean {\n const value = this.cookieService.get(CookieName.DarkMode);\n\n return value === EnabledCookieValue || value === EnabledCookieValueOldDesktop;\n }\n}\n"],"names":["DisabledCookieValue","EnabledCookieValueOldDesktop","EnabledCookieValue","DarkModeService","isEnabled","_isEnabled","constructor","cookieService","windowRef","getIsEnabled","toggle","writeCookie","nativeWindow","location","reload","value","putRaw","CookieName","DarkMode","expires","PERMANENT_COOKIE_EXPIRATION","get","ɵɵinject","CookieService","WindowRef","factory","ɵfac","providedIn","_DarkModeService"],"mappings":"+EAIMA,IAAAA,CAAAA,CAA8B,GAC9BC,CAAAA,CAAAA,CAAuC,GACvCC,CAAAA,CAAAA,CAA6B,IAUtBC,CAAe,CAAA,CAAA,IAAA,CAAtB,IAAOA,CAAP,CAAA,MAAOA,CAAe,CAGxB,IAAIC,SAAS,EAAA,CACT,OAAO,IAAA,CAAKC,UAChB,CAEAC,WAAAA,C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