{"version":3,"file":"flowbite-angular-theme.mjs","sources":["../../../../libs/flowbite-angular/theme/flowbite-theme.directive.ts","../../../../libs/flowbite-angular/theme/flowbite-angular-theme.ts"],"sourcesContent":["import type { FlowbiteTheme } from 'flowbite-angular';\n\nimport type { OnInit } from '@angular/core';\nimport { afterNextRender, Directive, inject, Injector, signal, untracked } from '@angular/core';\n\n/**\n * Use to give a clean API on the current application theme\n */\n@Directive({\n  standalone: true,\n  selector: '[flowbiteTheme]',\n})\nexport class FlowbiteThemeDirective implements OnInit {\n  private readonly injector = inject(Injector);\n\n  private readonly localStorageKey = 'color-theme';\n  private readonly _currentTheme = signal<FlowbiteTheme>('light');\n\n  public ngOnInit(): void {\n    afterNextRender(\n      () => {\n        this.toggleTheme(this.getLocalStorageTheme());\n      },\n      { injector: this.injector }\n    );\n  }\n\n  /**\n   * Get the application theme based on `signals`\n   */\n  public readonly currentTheme = this._currentTheme.asReadonly();\n\n  /**\n   * Get theme from the `localStorage`\n   *\n   * @returns The current theme saved in the `localStorage` with the key `color-theme`\n   */\n  public getLocalStorageTheme(): FlowbiteTheme {\n    return localStorage.getItem(this.localStorageKey) === 'dark' ? 'dark' : 'light';\n  }\n\n  /**\n   * Toggle the theme saved in the `localStorage` and available in `currentTheme`\n   *\n   * @param theme If provided, force the theme instead of toggling it between light and dark mode\n   */\n  public toggleTheme(theme?: FlowbiteTheme): void {\n    if (!theme) {\n      const tmpTheme = untracked(() => this.currentTheme());\n\n      if (tmpTheme === 'dark') theme = 'light';\n      else theme = 'dark';\n    }\n\n    this.setTheme(theme);\n  }\n\n  /**\n   * Set the theme inside the page\n   *\n   * @param theme Theme to apply\n   */\n  public setTheme(theme: FlowbiteTheme): void {\n    try {\n      localStorage.setItem(this.localStorageKey, theme);\n    } catch (error) {\n      console.warn('Failed to save theme to localStorage:', error);\n    }\n    this._currentTheme.set(theme);\n\n    theme === 'dark'\n      ? document.documentElement.classList.add('dark')\n      : document.documentElement.classList.remove('dark');\n  }\n}\n","/**\n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