import Component  from '../component.js';

export default class CalendarBody extends Component {
    constructor(parent) {
        let selector = 'tbody[contains(@class, "mat-calendar-body")]';
        super(parent, selector);
        // https://github.com/angular/components/blob/master/src/material/datepicker/calendar-body.html
    }
    getCalendarBodyRowByIndex(index) {
        return this.currentPath + '//tr[' + index + ']';
    }
    get calendarBodyLabel() {
        let path = '//td[contains(@class, "mat-calendar-body-label")]';
        return this.currentPath + path;
    }
    get calendarBodyCell() {
        let path = '//td[contains(@class, "mat-calendar-body-cell")]';
        return this.currentPath + path;
    }
    getCalendarBodyCellByIndex(index) {
        return '(' + this.calendarBodyCell + ')[' + index + ']';
    }
    get calendarBodyCellContent() {
        let path = '//div[contains(@class, "mat-calendar-body-cell-content")]';
        return this.calendarBodyCell + path;
    }
    getCalendarBodyCellContentByIndex(index) {
        return '(' + this.calendarBodyCellContent + ')[' + index + ']';
    }
    getCalendarCellByText(text) {
        let path = '/descendant-or-self::*[text()[normalize-space()="' + text + '"]]';
        return this.calendarBodyCellContent + path;
    }
    async isActiveCell() {
        let at = await (await $(this.calendarBodyCellContent)).getAttribute('class');
        if (at.includes('mat-calendar-body-selected')) {
            return true;
        } else {
            return false;
        }
    }
    get selectedCellValue() {
      return this.currentPath + '//div[contains(@class, "mat-calendar-body-selected")]';
    }
    get currentCellValue() {
      return this.currentPath + '//span[contains(@class, "mat-calendar-body-today")]';
    }
    calendarTDCellByText(text) {
      return this.currentPath + '//*[self::td][descendant::text()[contains(.,"'+text+'")]]';
    }
    async isCellDisabled(text) {
      return await (await (await $(this.calendarTDCellByText(text))).getAttribute('class')).includes('mat-calendar-body-disabled');
    }
}


