import { Component, OnInit } from '@angular/core';
import { ModalController, MenuController, NavController } from '@ionic/angular';
import { EventService } from '../../../services/event.service';
import { EnvService } from 'src/app/services/env.service';
import { AuthService } from 'src/app/services/auth.service';
import { IchambaService } from 'src/app/services/ichamba.service';
import { AlertService } from 'src/app/services/alert.service';

@Component({
  selector: 'app-redated',
  templateUrl: './redated.page.html',
  styleUrls: ['./redated.page.scss'],
  standalone: false
})
export class RedatedPage implements OnInit {

  ccontracts: any[] = [];
  ccontracts_dates: any[] = [];

  constructor(
    private modalController: ModalController,
    private menu: MenuController,
    private navCtrl: NavController,
    private events: EventService,
    private authService: AuthService,
    private alertService: AlertService,
    private ichambaService: IchambaService,
    private env: EnvService,
  ) {
    this.events.subscribe('refreshccontracts', (data) => {
      this.getccontracts();
    });
  }

  ngOnInit() {
    this.getccontracts();
  }

  getccontracts() {
    this.ichambaService.getCurrentcontracts().subscribe(
      data => {
        this.ccontracts = data;
        for (var i of this.ccontracts) {
          this.ccontracts_dates.push(new Date((new Date(i.date).toLocaleString('en-US') + ' UTC').replace("," ,"")).toLocaleDateString('es-US', { weekday: 'long', year: 'numeric', month: 'short', day: 'numeric', hour: 'numeric', minute:'numeric', timeZoneName: 'long'}));
        }
      }, error => {
        this.alertService.presentToast("Por favor contacte a soporte técnico, Estatus:" + error['status']);
      });
  }

}
