import { AuthServiceService } from './../../shared/auth-service.service';
import { Component, OnInit } from '@angular/core';
import { InternalPageService } from '../../shared/internal-page.service';

@Component({
  selector: 'app-hospital-content',
  templateUrl: './hospital-content.component.html',
  styleUrls: ['./hospital-content.component.css']
})

export class HospitalContentComponent implements OnInit {

  constructor(private internalService: InternalPageService, 
              private authSer:AuthServiceService) { }

  hospitalCenters = [];
  detailsField = [];

  expandedIndex:number;
  topArrow:boolean = true;
  bottomArrow:boolean = false;
  
  flag: boolean = false;
  
  catchEvent(event) {
    this.flag = true
    console.log(event)
  }

  hide(event) {
    this.flag = false;
  }
  


  ngOnInit() {

    this.expandedIndex = 0;

    this.internalService.getHospitalCenterList().subscribe(
      (responce) => {
        console.log(responce);
        this.hospitalCenters = responce['hospitals_centers'];
        this.showDescriptionDetails(this.hospitalCenters[0].fields[0]);
        console.log(this.hospitalCenters);
      },
      (error) => {
        console.log(error);
      }
    )
  }

  getInformationData(data) {
    for(let i = 0; i < this.hospitalCenters.length; i++) {
      if(data.id == this.hospitalCenters[i].id) {
        this.hospitalCenters[i].active = 1;
      } else if(data.id != this.hospitalCenters[i].id) {
        this.hospitalCenters[i].active = 0;
      }
       else{
        this.hospitalCenters[i].active = 0;
      }
    }
  }


  //show detail description 
  showDescriptionDetails(deatilData) {
    this.detailsField = deatilData;
  }

  open(data,i) {
    console.log(data);
    this.expandedIndex = i;
  }

  closeCollapse(i) {
    this.expandedIndex = -1;
  }



}
