import {Component, Input} from '@angular/core';
import {DateValue} from './searchHelperClasses.class';
import {FormControl} from "@angular/forms";
import { MatDatepickerInputEvent } from "@angular/material/datepicker";
@Component({
selector: 'date-filter',
template: `
{{dateValue.typesTitle[i]}}
`
})
export class DateFilterComponent {
@Input() dateValue = new DateValue("any");
@Input() filterId;
@Input() validDateFrom: boolean = true;
@Input() validDateTo: boolean = true;
// Initialized to specific date (09.10.2018).
public from;//: Object = { date: { year: 2018, month: 10, day: 9 } };
public to;//: Object = { date: { year: 2018, month: 10, day: 9 } };
public fromDate;
public toDate;
constructor() {
}
ngOnInit() {
this.updateDefaultRangeDates(this.dateValue.from,this.dateValue.to);
}
updateDefaultRangeDates(df:Date,dt:Date){
this.fromDate = new FormControl(df);
this.toDate = new FormControl(dt);
}
typeChanged(type:string){
this.dateValue.setDatesByType(type);
this.updateDefaultRangeDates(this.dateValue.from, this.dateValue.to);
}
fromDateChanged(event: MatDatepickerInputEvent) {
this.dateValue.from = event.value;
//console.info("FROM: "+Dates.getDateToString(this.dateValue.from));
}
toDateChanged(event: MatDatepickerInputEvent) {
this.dateValue.to = event.value;
//console.info("TO: "+Dates.getDateToString(this.dateValue.to));
}
}