import { Component, OnInit } from '@angular/core';
import { Server } from "../../../server";
import { ServerGridModel } from "../../../models/serverGrid.model";

@Component({
  selector: 'app-servers',
  templateUrl: './servers.component.html'
})
export class ServersComponent implements OnInit {
  private grid: ServerGridModel;

  private xArray: number[];
  private yArray: number[];

  private serverLookup: number[][] = [];
  private unknownServers: number[] = [];

  constructor(private server: Server) {
    this.grid = server.serverGrid;
    this.xArray = Array.from(Array(this.grid.totalGridsX).keys());
    this.yArray = Array.from(Array(this.grid.totalGridsY).keys());
    this.grid.servers.forEach((i, index) => {
      if (i.gridX < this.grid.totalGridsX && i.gridY < this.grid.totalGridsY) {
        if (this.serverLookup[i.gridX] === undefined)
          this.serverLookup[i.gridX] = [];
        this.serverLookup[i.gridX][i.gridY] = index;
      } else {
        this.unknownServers.push(index);
      }
    });
  }

  ngOnInit() {
  }
}
