import { Component, OnInit } from '@angular/core';
import { Server } from "../../../../server";
import { ServerModel } from "../../../../models/atlasData/server.model";
import { IslandInstanceModel } from "../../../../models/atlasData/island-instance.model";
import { ActivatedRoute } from "@angular/router";

@Component({
  selector: 'app-island-instance',
  templateUrl: './island-instance.component.html'
})
export class IslandInstanceComponent implements OnInit {
  private cell: ServerModel;
  private cellIndex;
  private island: IslandInstanceModel;
  private islandIndex;

  private minX: number;
  private maxX: number;
  private minY: number;
  private maxY: number;
  private minRot: number = 0;
  private maxRot: number = 360;

  constructor(private server: Server, private route: ActivatedRoute) {
  }

  ngOnInit() {
    this.cellIndex = this.route.snapshot.paramMap.get('index');
    this.islandIndex = this.route.snapshot.paramMap.get('islandIndex');
    this.cell = this.server.serverGrid.servers[this.cellIndex];
    this.island = this.cell.islandInstances[this.islandIndex];
    this.minX = this.cell.gridX * this.server.serverGrid.gridSize;
    this.maxX = this.minX + this.server.serverGrid.gridSize;
    this.minY = this.cell.gridY * this.server.serverGrid.gridSize;
    this.maxY = this.minY + this.server.serverGrid.gridSize;
  }
  // TODO Need to update subLevels in parent Cell when updating X and Y...

  // Issue with text arrays and editing jumps on each change.
  trackByFn(index: any, item: any) {
    return index;
  }

  private removeTreasureLocation(index: number) {
    this.island.treasureMapSpawnPoints.splice(index, 1);
  }

  private removeCampLocation(index: number) {
    this.island.wildPirateCampSpawnPoints.splice(index, 1);
  }
}
