import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from "@angular/router";
import { Server } from "../../../../server";
import { ServerModel } from "../../../../models/atlasData/server.model";
import { DiscoveryZoneModel } from "../../../../models/atlasData/discovery-zone.model";
import * as ExplorerNotes from '../../../../../data/explorer-notes.json';

@Component({
  selector: 'app-discovery-zone',
  templateUrl: './discovery-zone.component.html'
})
export class DiscoveryZoneComponent implements OnInit {
  private cell: ServerModel;
  private cellIndex;
  private discovery: DiscoveryZoneModel;
  private discoIndex;

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

  private explorerNotes;

  private discoveryVolumeNameOptions: object = {};
  private discoveryVolumeNameOptionKeys: string[] = [];

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

  ngOnInit() {
    this.cellIndex = this.route.snapshot.paramMap.get('index');
    this.discoIndex = this.route.snapshot.paramMap.get('discoIndex');
    this.cell = this.server.serverGrid.servers[this.cellIndex];
    this.discovery = this.cell.discoZones[this.discoIndex];
    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;
    this.explorerNotes = (ExplorerNotes as any).default;

    this.cell.islandInstances.forEach(i => {
      const islandData = this.server.islands.islandData[i.name];
      if (islandData.discoveryVolumeNames.length === 0 ) return;
      islandData.discoveryVolumeNames.forEach(
        i => {
          this.discoveryVolumeNameOptions[i.name] = i;
          this.discoveryVolumeNameOptionKeys.push(i.name);
        }
      )
    });
    this.discoveryVolumeNameOptionKeys = this.discoveryVolumeNameOptionKeys.sort();
  }

  private setExplorerNote(option: string) {
    this.discovery.explorerNoteIndex = parseInt(option);
  }

  private setDiscoveryVolumeName(option: string) {
    console.log(this.discoveryVolumeNameOptions[option]);
  }

  private setLocationCenterOfCell() {
    this.discovery.worldX = this.minX + ( this.server.serverGrid.gridSize / 2 );
    this.discovery.worldY = this.minY + ( this.server.serverGrid.gridSize / 2 );
  }
}
