import { Component, OnInit } from '@angular/core';
import { MatDialogRef } from '@angular/material/dialog';
import { EncService } from '../../../../services/enc.service';

@Component({
    selector: 'app-locate-pcc',
    templateUrl: './locate-pcc.component.html',
    styleUrl: './locate-pcc.component.css',
    standalone: false
})
export class LocatePccComponent implements OnInit {
  coords = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'];
  xCoords: string[];
  yCoords: string[];
  selectedXCoord: string;

  constructor(
    private _dialogRef: MatDialogRef<LocatePccComponent>,
    private _encService: EncService,
  ) {
    this.xCoords = [];
    this.yCoords = [];
    this.selectedXCoord = '';
  }

  ngOnInit(): void {
    let yCoordsAux: string[] = [];

    for(const coord of this.coords){
      this.xCoords.push(`A${coord}`);
      yCoordsAux.push(coord);
    }

    yCoordsAux.reverse();
    yCoordsAux.push('');

    this.yCoords = yCoordsAux;
  }

  changeSelectedXCoord(coordX: string){
    if(this.selectedXCoord == ''){
      this.selectedXCoord = coordX;
    }else{
      this.selectedXCoord = '';
    }
  }

  async selectPCCCoords(coordX: string, coordY: string){
    let coordsEnc = await this._encService.encrypt(`${coordY}${coordX}`);
    this._dialogRef.close(coordsEnc);
  }
}
