import {Component, OnDestroy, OnInit} from '@angular/core';
import {Subscription} from 'rxjs';
import {ThemeService} from './theme.service';
import {THEME_MODE} from '@custom-types/constant';


@Component({
  standalone: true,
  imports: [],
  selector: 'app-theme',
  templateUrl: './theme.component.html',
  styleUrl: './theme.component.scss'
})
export class ThemeComponent implements OnInit, OnDestroy {
  isDarkMode: boolean = false;
  private themeSubscription: Subscription | null = null;

  constructor(private themeService: ThemeService) {
  }

  ngOnInit(): void {
    this.themeSubscription = this.themeService.theme$.subscribe(theme => {
      this.isDarkMode = theme === THEME_MODE.DARK;
    });
  }

  toggleTheme(): void {
    this.isDarkMode = this.themeService.toggleTheme() === THEME_MODE.DARK;
  }

  ngOnDestroy(): void {
    if (this.themeSubscription) {
      this.themeSubscription.unsubscribe();
    }
  }


}
