import { Component } from '@angular/core';
import {CurrencyPipe} from '@angular/common';
import { NavController, ModalController, LoadingController, AlertController } from 'ionic-angular';

import { DoctorService } from '../../services/doctor.service';
import { Pata } from '../../pata';
import { environment } from "../../environments/environment"
import * as moment from 'moment';
import { VerRecorridoPage } from '../ver-recorrido/ver-recorrido';
import { UserService } from '../../services/user.service';

@Component({
  selector: 'page-historial',
  templateUrl: 'historial.html'
})
export class HistorialPage {
  public arrayDataReq: any;
  shownGroup = null;
  requirements: any;
  finanzas: any = [];
  thc: any = [];
  public user: any = { id: '0'};
  appInvite: boolean = true;

  constructor(
    public navCtrl: NavController,
    public modalCtrl: ModalController,
    public loadingCtrl: LoadingController,
    private alertCtrl: AlertController,
    public userService: UserService,
    public service: Pata,
    private doctorService: DoctorService) {
      this.appInvite = this.service.appInvite;
      this.userService.getProfile().subscribe((result:any)=>{
        this.user = result;
      });
  }
  ionViewDidEnter(){
    this.getStats();
  }
  

  getStats() {
    this.doctorService.getHistory().subscribe((data:any)=>{
      this.finanzas = data.finance;
      this.thc=data.thc;
    });
  };
  dateformat(fecha){
    //var fecha_mm = moment(fecha);
    //return moment(fecha_mm.format(),moment.ISO_8601).format();
    fecha = fecha.replace(' ','T');
    let f = new Date(fecha);
    let dd = f.getDate();
    let mm = f.getMonth() + 1; //January is 0!
    let sdd:string = '';
    let smm:string = '';

    let yyyy = f.getFullYear();

    if (dd < 10) {
      sdd = '0' + dd;
    } else { sdd = dd+''; }
    if (mm < 10) {
      smm = '0' + mm;
    } else { smm = mm+''; }
    
    var today = sdd + '/' + smm; // + '/' + yyyy;
    return today;
  }
  doRefresh(refresher) {
    this.getStats();
    setTimeout(() => {
      refresher.complete();
    }, 0);
  }

}


