import Component  from '../component.js'
import MatCalendarHeader from './mat-calendar-header.js'
import MonthView from './month-view.js'
import YearView from './year-view.js'
import MatMultiYearView from './mat-multi-year-view.js'


export default class MatCalendar extends Component {
    constructor(parent) {
      let selector = 'mat-calendar[contains(@class, "mat-calendar")]';
      super(parent, selector);
    }
    // https://github.com/angular/components/blob/master/src/material/datepicker/calendar.html

    get matCalendarHeaderCO() {
        return new MatCalendarHeader(this.currentPath);
    }
    get matCalendarContent() {
        let path = '//div[contains(@class, "mat-calendar-content")]';
        return this.currentPath + path;
    }
    get calendarMonthViewCO() {
        return new MonthView(this.matCalendarContent);
    }
    get calendarYearViewCO() {
        return new YearView(this.matCalendarContent);
    }
    get calendarMultiYearViewCO() {
        return new MatMultiYearView(this.matCalendarContent);
    }
    async calendarView() {
        let month = await (await $(this.matCalendarContent + '//mat-month-view')).isExisting();
        let year = await (await $(this.matCalendarContent + '//mat-year-view')).isExisting();
        let multiYear = await (await $(this.matCalendarContent + '//mat-multi-year-view')).isExisting();

        if (month) {
            return 'month view';
        } else if (year) {
            return 'year view';
        } else if (multiYear) {
            return 'multi year view';
        } else {
            throw new Error('mat-calendar component object needs to be revised');
        }
    }
}
