import ScreenSizeDetection from '../ScreenSizeDetection';

export class NewsController {

  private entities: Array<any>;
  public itemsPerPage: number = 7;
  public screensize: string;

  constructor(
    private $timeout
  ) {
    this.subscribeObservables();
  }

  private subscribeObservables(): void {
    ScreenSizeDetection.get().subscribe(screensize => {
      this.screensize = screensize;
      let itemsPerPage;
      if (screensize === 'xs' || screensize === 'sm') {
        itemsPerPage = 3;
      } else {
        itemsPerPage = 7;
      }
      this.$timeout(() => {
        this.itemsPerPage = itemsPerPage;
      })
    });
  }

  $onInit() {
    this.entities = window['news'];
  }
}
