import { Component, OnInit, ViewChild } from '@angular/core';
import { Calendar } from '@awesome-cordova-plugins/calendar/ngx';
import { IonDatetime } from '@ionic/angular';
import { format, parseISO } from 'date-fns';

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

    @ViewChild('popoverDatetime') popDate;

    dateValue = '';
    dateValue2 = '';

    constructor(private calendar: Calendar) { }

    ngOnInit() {
    }

    ionViewDidEnter() {
        this.listCalendar()
    } 
    listCalendar() {
        this.calendar.listCalendars().then(
            success => {
                console.log(success);
            }
        ).catch( error => console.log(error) )
    }

    confirm() {
        this.popDate.nativeElement.confirm();
    }

    reset() {
        this.popDate.nativeElement.reset();
    }

    formatDate(value: string) {
        return format(parseISO(value), 'MMM dd yyyy');
    }

}
