import { Injectable, computed, inject } from '@angular/core';

import { deLanguage } from '../../languages/de';
import { enLanguage } from '../../languages/en';
import type { LanguageCode, LanguagePack } from '../../languages/language.types';
import { LanguagePreferenceService } from './language-preference.service';

@Injectable({ providedIn: 'root' })
export class LanguageService {
  private readonly languagePreferenceService = inject(LanguagePreferenceService);

  readonly languageCode = this.languagePreferenceService.languageCode;
  readonly isLanguageConfirmed = this.languagePreferenceService.isLanguageConfirmed;
  readonly content = computed<LanguagePack>(() => this.getPack(this.languageCode()));

  initializeFromStorage(): LanguageCode {
    return this.languagePreferenceService.initializeFromStorage();
  }

  confirmLanguage(code: LanguageCode): void {
    this.languagePreferenceService.confirmLanguage(code);
  }

  getPack(code: LanguageCode): LanguagePack {
    return code === 'de' ? deLanguage : enLanguage;
  }
}
