import { NgxSpinnerService } from 'ngx-spinner';
import { AuthServiceService } from './../../shared/auth-service.service';
import { ActivatedRoute } from '@angular/router';
import { Component, OnInit } from '@angular/core';
import { ExternalPageService } from '../../shared/external-page.service';

@Component({
  selector: 'app-external-managaments',
  templateUrl: './external-managaments.component.html',
  styleUrls: ['./external-managaments.component.css']
})
export class ExternalManagamentsComponent implements OnInit {

  typePage: string = '';
  data = [];
  detailsField = {
    title_en: '',
    title: '',
    description: '',
    description_en: '',
  }

  constructor(private route: ActivatedRoute,
    private authSer: AuthServiceService, 
    private spinner: NgxSpinnerService,
    private externalService: ExternalPageService) {
      this.spinner.show();
     }

  ngOnInit() {
    this.authSer.homeActivate = false;
    //to add class active if mangaments route activate
    this.externalService.getHeader().subscribe(
      (responce) => {
        this.externalService.headerMenus = responce['parents'];
        for(let i = 0; i < this.externalService.headerMenus.length; i++) {
          if(this.externalService.headerMenus[i].id == 20) {
            this.externalService.headerMenus[i].active = 1;
          } else {
            this.externalService.headerMenus[i].active = 0;
          }
        }
        this.spinner.hide();
      },
      (error) => {
        console.log(error);
      }
    );

    this.externalService.getHospitalMangamentsData('managements').subscribe(
      (responce) => {
        console.log(responce);
        this.data = responce['managements'];
        console.log('data mangaments', this.data);
        this.showDescriptionDetails(this.data[0].fields[0]);
        this.spinner.hide();
      },
      (error) => {
        console.log(error);
      }
    );
  }

   //show data of filed if click
   showDescriptionDetails(fieldData) {
    console.log(fieldData);
    this.detailsField = {
      title: fieldData.title,
      title_en: fieldData.title_en,
      description: fieldData.description,
      description_en: fieldData.description_en,
    }
    console.log(this.detailsField);
  }

}
