import {Component, OnInit} from '@angular/core';
import {ApiService} from "../../../../core/api/api.service";

@Component({
	selector: 'kt-calendario',
	templateUrl: './calendario.component.html',
	styleUrls: ['./calendario.component.scss']
})

export class CalendarioComponent implements OnInit {

	viewDate: Date = new Date();
	serviciosRaw: any[] = [];
	titulo = "Agenda"
	isLoading = true;

	constructor(private api: ApiService) {
	}

	ngOnInit() {
		this.cargarServicios();
	}

	cargarServicios(): void {
		const startDay = this.viewDate;

		let data = {
			start_day: startDay.getFullYear() + '-' + (startDay.getMonth() + 1) + '-' + startDay.getDate(),
			end_day: startDay.getFullYear() + '-' + (startDay.getMonth() + 1) + '-' + startDay.getDate()
		}

		this.isLoading = true;
		this.api.agenda.create(data).subscribe(res => {
			this.serviciosRaw = res;
			this.isLoading = false;
		}, () => {
			this.isLoading = false;
		});
	}

	btnChangeDate(): void {
		this.cargarServicios();
	}

	irAnterior(): void {
		this.viewDate = new Date(this.viewDate.setDate(this.viewDate.getDate() - 1));
		this.cargarServicios();
	}

	irHoy(): void {
		this.viewDate = new Date();
		this.cargarServicios();
	}

	irSiguiente(): void {
		this.viewDate = new Date(this.viewDate.setDate(this.viewDate.getDate() + 1));
		this.cargarServicios();
	}
}
