import {Inject, Injectable} from '@angular/core';
import {DOCUMENT} from "@angular/common";

@Injectable({
    providedIn: 'root'
})
export class ThemeService {

    private currentTheme = 'light';

    constructor(@Inject(DOCUMENT) private document: Document) {
    }

    setTheme(theme: string) {
        let themeLink = this.document.getElementById('app-theme') as HTMLLinkElement;

        if (this.currentTheme != theme) {
            this.currentTheme = theme;
            if (themeLink) {
                themeLink.href = this.currentTheme + '.css';
            }
        }
    }

    isDarkThemeEnabled() {
        return this.currentTheme == 'dark';
    }
}
