import { AuthServiceService } from './../../shared/auth-service.service';
import { ExternalPageService } from './../../shared/external-page.service';
import { Component, OnInit } from '@angular/core';
import {MapsAPILoader} from '@agm/core';
import * as $ from 'jquery';

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

  constructor(private externalService: ExternalPageService, 
    private authSer:AuthServiceService) { }

  reports = [];
  events = [];
  services = [];
  secondAdvertisiment = [];
  hypnosisSections = [];
  intensiveCare = []; 
  recordsOfMonth = [];
  achievements = [];

  title: string = 'My first AGM project';
  lat: number;
  lng: number;

  firstAdvertisiment = [] //[1,2,3,4,5,6,7,8,9].map((i)=> `https://picsum.photos/640/480?image=${i}`);
  //myCarouselImages =[1,2,3,4,5,6].map((i)=>`https://picsum.photos/640/480?image=${i}`);
  //firstAdvertisiment = [];
  mySlideOptions={items: 3, dots: false, nav: true};
  myCarouselOptions={items: 3, dots: true, nav: true};

  

  ngOnInit() {

    //get content data of external pages
    this.externalService.getContentData().subscribe(
      (responce) => {
        console.log(responce);
        this.reports = responce['data'].reports;
        for(let i = 0; i < this.reports.length; i++) {
          if(this.reports[i].description.length > 100) {
            this.reports[i].description = this.reports[i].description.substring(0,300) + '.......';
            this.reports[i].description_en = this.reports[i].description_en.substring(0,300) + '.......';
          }
        }
        this.events = responce['data'].events;
        this.services = responce['data'].external_services;
        this.firstAdvertisiment = responce['data'].first_advertising_services_row;
        this.secondAdvertisiment = responce['data'].second_advertising_services_row;
        this.hypnosisSections = responce['data'].visiting_times_hs;
        this.intensiveCare = responce['data'].visiting_times_ic;
        this.recordsOfMonth = responce['data']['statistics'];
        this.achievements = responce['data'].external_achievements;
        this.lat = responce['data']['reach_map'].latitude;
        this.lng = responce['data']['reach_map'].longitude;
        console.log('fiiiiiiiiiiiiiiiiiiiii' , this.firstAdvertisiment);
      },
      (error) => {
        console.log(error);
      }
    );


  }

  

}
