import {Injectable} from '@angular/core';
import {SCAppConfigurationMenuCategory} from '@openstapps/core';
import {ConfigProvider} from '../../config/config.provider';
import {NGXLogger} from 'ngx-logger';

@Injectable({
  providedIn: 'root',
})
export class NavigationService {
  constructor(
    private configProvider: ConfigProvider,
    private logger: NGXLogger,
  ) {}

  async getMenu() {
    let menu: SCAppConfigurationMenuCategory[] = [];
    try {
      menu = (await this.configProvider.getValue(
        'menus',
      )) as SCAppConfigurationMenuCategory[];
    } catch (error) {
      this.logger.error(`error from loading menu entries: ${error}`);
    }

    // TODO: move this menu item to the config (backend)
    menu[1].items.unshift({
      icon: 'library',
      route: '/library-account',
      title: 'library account',
      translations: {
        de: {
          title: 'Bibliothekskonto',
        },
        en: {
          title: 'Library account',
        },
      },
    });
    return menu;
  }
}
