import Component  from '../component.js'
import CoEuiButton from './eui-button.js'
import CoEuiIcon from './eui-icon.js'
import CoEuiLabel from './eui-label.js'
import MatDatepicker from '../material/mat-datepicker.js'
import MatDatepickerActions from '../material/mat-datepicker-actions.js'
import CoEuiInputGroup from './eui-input-group.js'
import CoEuiInputText from './eui-input-text.js'
import CdkOverlayContainer from '../cdk-overlay-container.js'
import MatDatepickerContent from '../material/mat-datepicker-content.js'

export default class CoEuiDatepicker extends Component {
  constructor(parent) {
    let selector = 'eui-datepicker';
    super(parent, selector);
    //https://citnet.tech.ec.europa.eu/CITnet/stash/projects/CSDR/repos/eui/browse/packages/components/eui-datepicker/eui-datepicker.component.html?at=support/13.x
  }
  get wrapper() {
    return this.currentPath + '//div[contains(@class, "eui-datepicker__wrapper")]';
  }
  async isDatepickerBlock() {
    return await (await $(this.wrapper + '/self::div[contains(@class, "eui-datepicker__wrapper--responsive")]')).isExisting();
  }
  get inputGroupCo() {
    return new CoEuiInputGroup(this.wrapper);
  }
  get inputGroupAddon() {
    return this.inputGroupCo.currentPath + '//div[contains(@class, "eui-input-group-addon")]';
  }
  get inputTextCo() {
    return new CoEuiInputText(this.inputGroupAddon);
  }
  async isReadOnly() {
    return await (await $(this.inputTextCo.currentPath + '/self::input[@readonly]')).isExisting();
  }
  async isClearable() {
    return await (await $(this.inputTextCo.currentPath + '/self::input[@euiClearable]')).isExisting();
  }
  async hasNoButton() {
    return await (await $(this.inputTextCo.currentPath + '/self::input[contains(@class, "eui-datepicker--no-button")]')).isExisting();
  }
  async hasLongFormat() {
    return await (await $(this.inputTextCo.currentPath + '/self::input[contains(@class, "eui-datepicker--long-format")]')).isExisting();
  }
  async hasLongFormat() {
    return await (await $(this.inputTextCo.currentPath + '/self::input[contains(@class, "eui-datepicker--long-format")]')).isExisting();
  }
  async inputDateFormat() {
    return await (await (await $(this.inputTextCo.currentPath))).getAttribute('placeholder');
  }
  get matDatepickerCo() {
    return new MatDatepicker(this.inputGroupAddon);
  }
  get matDatepickerActionsCo() {
    return new MatDatepickerActions(this.matDatepickerCo);
  }
  async hasActionButtons() {
    return await (await $(this.matDatepickerActionsCo.currentPath)).isExisting();
  }
  get footer() {
    return this.matDatepickerActionsCo.currentPath + '//div[contains(@class, "eui-datepicker__footer")]';
  }
  async hasTodayButton() {
    return await (await $(this.footer)).isExisting();
  }
  get todayButtonCo() {
    return new CoEuiButton(this.footer);
  }
  get todayIconCo() {
    return new CoEuiIcon(this.todayButtonCo);
  }
  get todayLabelCo() {
    return new CoEuiLabel(this.todayButtonCo);
  }
  get cancelButton() {
    return new CoEuiButton(this.matDatepickerActionsCo).currentPath + '/self::button[contains(text(),"Cancel")]';
  }
  get applyButton() {
    return new CoEuiButton(this.matDatepickerActionsCo).currentPath + '/self::button[contains(text(),"Apply")]';
  }
  get datepickerButton() {
    return new CoEuiButton(this.inputGroupAddon).currentPath + '/self::button[@aria-haspopup="dialog"]';
  }
  async hasButton() {
    return await (await $(this.datepickerButton)).isExisting();
  }
  async isButtonDisabled() {
    return await (await $(this.datepickerButton + '/self::button[contains(@class,"disabled")]')).isExisting();
  }
  get openCalendarIcon() {
    return new CoEuiIcon(this.datepickerButton).currentPath + '/self::span[@aria-label="Open Calendar"]';
  }
  get openCalendarLabel() {
    return this.datepickerButton + '//span[not(@euiicon)]';
  }
  async hasTogglerLabel() {
    return await (await $(this.openCalendarLabel)).isExisting();
  }
  // is not in the template but put here due to datepicker-actions implementation done for ux
  get overlayContainerCO() {
    return new CdkOverlayContainer('//body');
  }
  get matDatepickerContentCo() {
    return new MatDatepickerContent(this.overlayContainerCO.overlayPane);
  }
}


