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

@Component({
  selector: 'app-locate-pcc',
  templateUrl: './locate-pcc.component.html',
  styleUrls: ['./locate-pcc.component.css']
})
export class LocatePccComponent implements OnInit{
  yCoords = ['-', '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', 'AB'];
  xCoords = ['-', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16',
  '17', '18', '19', '20', '21', '22', '23', '24', '25', '26', '27'];

  map: Map<string, any>;
  elements = [
    {coord: '0N', element: 'PDC', code: 'PDCXX', color: '#337a91'},
    {coord: '1F', element: 'BAT', code: 'BATXX', color: '#8e3596'},
    {coord: '1I', element: 'BAT', code: 'BATXX', color: '#cfc763'},
    {coord: '1R', element: 'SAP/IHM OA', code: 'SAIOA', color: '#3ba896'},
    {coord: '2F', element: 'UPS', code: 'UPSXX', color: '#d4735b'},
    {coord: '2I', element: 'UPS', code: 'UPSXX', color: '#e62e34'},
    {coord: '2R', element: 'PIU/DDP', code: 'PIUDD', color: '#065240'},
    {coord: '2V', element: 'ODF', code: 'ODFXX', color: '#94e687'},
    {coord: '3F', element: 'BAT', code: 'BATXX', color: '#05c9f0'},
    {coord: '3I', element: 'BAT', code: 'BATXX', color: '#574494'},
    {coord: '3Ñ', element: 'SRV-COMMS PCC-A', code: 'SRCPA', color: '#4dd907'},
    {coord: '3R', element: 'CCTV', code: 'CCTVX', color: '#3d36ba'},
    {coord: '4F', element: 'BAT', code: 'BATXX', color: '#9336ba'},
    {coord: '4I', element: 'BAT', code: 'BATXX', color: '#ba8336'},
    {coord: '4Ñ', element: 'SRV-COMMS PCC-B', code: 'SRCPB', color: '#a9ba36'},
    {coord: '4R', element: 'LTE', code: 'LTEXX', color: '#36ba4e'},
    {coord: '4V', element: 'AC', code: 'ACXXX', color: '#ba4336'},
    {coord: '5Ñ', element: 'SRV-COMMS PCC-C', code: 'SRCPC', color: '#a1107f'},
    {coord: '6F', element: 'UPS', code: 'UPSXX', color: '#c781b7'},
    {coord: '6I', element: 'UPS', code: 'UPSXX', color: '#060733'},
    {coord: '6R', element: 'TEL/GDA', code: 'TELGD', color: '#173306'},
    {coord: '6V', element: 'AC', code: 'ACXXX', color: '#06332a'},
    {coord: '7Ñ', element: 'SCADA E&M', code: 'SCAEM', color: '#47edcc'},
    {coord: '7R', element: 'CLK/CDA', code: 'CLKCD', color: '#1629f7'},
    {coord: '8B', element: 'INTERRUPTOR ELECTROMAGNÉTICO 3x1600 AMP', code: 'IE316', color: '#f0f716'},
    {coord: '8R', element: 'RMS', code: 'RMSXX', color: '#f71629'},
    {coord: '9V', element: 'LTE-B', code: 'LTEBX', color: '#8e16f7'},
    {coord: '10B', element: 'TRANSFORMADOR TIPO SECO 500 KVA', code: 'TTS5K', color: '#f716e8'},
    {coord: '11U', element: 'ARMARIOS RECUPERACIÓN DE MANDO L1 A L6', code: 'ARM16', color: '#f78316'},
    {coord: '11V', element: 'ARMARIOS RECUPERACIÓN DE MANDO L1 A L6', code: 'ARM16', color: '#3cf716'},
    {coord: '11W', element: 'MDF', code: 'MDFXX', color: '#167cf7'},
    {coord: '11Y', element: 'ODF', code: 'ODFXX', color: '#c7f716'},
    {coord: '12F', element: 'UPS', code: 'UPSXX', color: '#576620'},
    {coord: '12J', element: 'COBRE', code: 'COBRE', color: '#205266'},
    {coord: '12L', element: 'COBRE', code: 'COBRE', color: '#382066'},
    {coord: '12M', element: 'COBRE', code: 'COBRE', color: '#663720'},
    {coord: '12Ñ', element: 'RED', code: 'REDXX', color: '#662022'},
    {coord: '12O', element: 'RED', code: 'REDXX', color: '#337a91'},
    {coord: '12Q', element: 'RED', code: 'REDXX', color: '#8e3596'},
    {coord: '13B', element: 'TABLERO A', code: 'TABLA', color: '#cfc763'},
    {coord: '14F', element: 'BAT', code: 'BATXX', color: '#3ba896'},
    {coord: '15F', element: 'UPS', code: 'UPSXX', color: '#d4735b'},
    {coord: '15K', element: 'CCTV L1 A L6', code: 'CCT16', color: '#e62e34'},
    {coord: '15Ñ', element: 'RED C Y S L1 A L6', code: 'RCS16', color: '#065240'},
    {coord: '15W', element: 'TRACCIÓN', code: 'TRACC', color: '#94e687'},
    {coord: '16B', element: 'TABLERO P', code: 'TABLP', color: '#05c9f0'},
    {coord: '16F', element: 'BAT', code: 'BATXX', color: '#574494'},
    {coord: '16K', element: 'CCTV L1 A L6', code: 'CCT16', color: '#4dd907'},
    {coord: '16Ñ', element: 'RED C Y S L1 A L6', code: 'RCS16', color: '#3d36ba'},
    {coord: '16W', element: 'TRACCIÓN', code: 'TRACC', color: '#9336ba'},
    {coord: '17W', element: 'DISTRIBUCIÓN DE ENERGÍA L2', code: 'DIEL2', color: '#ba8336'},
    {coord: '19B', element: 'TABLERO B', code: 'TABLB', color: '#a9ba36'},
    {coord: '19K', element: 'TELECOM L2', code: 'TELL2', color: '#36ba4e'},
    {coord: '19Ñ', element: 'SERVIDOR BASE DE DATOS L2', code: 'SBDL2', color: '#ba4336'},
    {coord: '19R', element: 'SERVIDOR DE APLICACIONES L2', code: 'SEAL2', color: '#a1107f'},
    {coord: '19W', element: 'DISTRIBUCIÓN DE ENERGÍA L3', code: 'DIEL3', color: '#c781b7'},
    {coord: '20F', element: 'UPS', code: 'UPSXX', color: '#060733'},
    {coord: '20K', element: 'TELECOM L3', code: 'TELL3', color: '#173306'},
    {coord: '20Ñ', element: 'SERVIDOR BASE DE DATOS L3', code: 'SBDL3', color: '#06332a'},
    {coord: '20R', element: 'SERVIDOR DE APLICACIONES L3', code: 'SEAL3', color: '#47edcc'},
    {coord: '20W', element: 'DISTRIBUCIÓN DE ENERGÍA L4', code: 'DIEL4', color: '#1629f7'},
    {coord: '21B', element: 'TRANSFORMADOR TIPO SECO 500 KVA', code: 'TTS5K', color: '#f0f716'},
    {coord: '21F', element: 'BAT', code: 'BATXX', color: '#f71629'},
    {coord: '22F', element: 'UPS', code: 'UPSXX', color: '#8e16f7'},
    {coord: '22K', element: 'TELECOM L4', code: 'TELL4', color: '#f716e8'},
    {coord: '22Ñ', element: 'SERVIDOR BASE DE DATOS L4', code: 'SBDL4', color: '#f78316'},
    {coord: '22R', element: 'SERVIDOR DE APLICACIONES L4', code: 'SEAL4', color: '#3cf716'},
    {coord: '22W', element: 'DISTRIBUCIÓN DE ENERGÍA L5', code: 'DIEL5', color: '#167cf7'},
    {coord: '23F', element: 'BAT', code: 'BATXX', color: '#c7f716'},
    {coord: '23K', element: 'TELECOM L5', code: 'TELL5', color: '#576620'},
    {coord: '23Ñ', element: 'SERVIDOR BASE DE DATOS L5', code: 'SBDL5', color: '#205266'},
    {coord: '23R', element: 'SERVIDOR DE APLICACIONES L5', code: 'SEAL5', color: '#382066'},
    {coord: '24B', element: 'INTERRUPTOR ELECTROMAGNÉTICO 3x1600 AMP', code: 'IE316', color: '#663720'},
    {coord: '24K', element: 'TELECOM L6', code: 'TELL6', color: '#662022'},
    {coord: '24Ñ', element: 'SERVIDOR BASE DE DATOS L6', code: 'SBDL6', color: '#827474'},
    {coord: '24R', element: 'SERVIDOR DE APLICACIONES L6', code: 'SEAL6', color: '#b4aae6'},
    {coord: '24W', element: 'DISTRIBUCIÓN DE ENERGÍA L6', code: 'DIEL6', color: '#120d2e'},
  ];

  constructor(
    private _dialogRef: MatDialogRef<LocatePccComponent>,
    private _encService: EncService,
  ) {
    this.map = new Map();
  }

  ngOnInit(): void {
    for(let x = 0; x < this.xCoords.length; x++){
      let xCoord = this.xCoords[x];
      for(let y = 0; y < this.yCoords.length; y++){
        let yCoord = this.yCoords[y];
        let coord = `${xCoord}${yCoord}`;

        let element = this.elements.filter(item => item.coord == coord);
        if(element.length > 0){
          this.map.set(coord, element[0]);
        }
      }
    }
  }

  async closePCCLocations(element: any){
    let dataEnc = await this._encService.encrypt(`${element.coord}|${element.element}|${element.code}`);
    this._dialogRef.close(dataEnc);
  }
}
