import { Component, Directive, Input, OnInit } from '@angular/core';
import { TranslateService } from '@ngx-translate/core';
import { HeaderService, IMenuItem, RouterExtService, UserService } from '../../shared';

@Component({
  selector: 'knk-published-content',
  styleUrls: ['./knk-published-content.component.scss'],
  templateUrl: './knk-published-content.component.pug'
})
export class KnkPublishedContentComponent implements OnInit {
  lang: string;
  menuItems: IMenuItem[];

  constructor(private translateService: TranslateService,
              private routerExt: RouterExtService,
              private userService: UserService,
              private headerService: HeaderService) {
  }

  ngOnInit(): void {
    this.lang = this.translateService.currentLang || this.translateService.defaultLang;
    this.menuItems = this.headerService.getPublishedMenu();

    this.userService.loadUser().subscribe(accounts => {
      if (!accounts.user.userIsKnokser) {
        this.routerExt.goToHome();
      }
    }, error => {
      this.routerExt.goToHome();
    });
  }
}
