import Component  from '../component.js';
import CoUxButton from '../7x/ux-button.js';
import CdkOverlayContainer from '../7x/cdk-overlay-container.js';
import MatDatepickerContent from '../material/mat-datepicker-content.js';

export default class CoUxDatepicker extends Component {

  constructor(parent) {
    let selector = 'ux-datepicker';
    super(parent, selector);
    //https://citnet.tech.ec.europa.eu/CITnet/stash/projects/CSDR/repos/eui/browse/packages/core/src/lib/commons/ux-components/ux-datepicker/ux-datepicker.component.html?at=refs%2Fheads%2Fsupport%2F7.x
  }
  get dataE2e() {
    let path = '//div[@data-e2e = "ux-datepicker"]';
    return this.currentPath + path;
  }
  get datepickerDiv() {
    return this.dataE2e + '/div';
  }
  get datepickerInput() {
    return this.datepickerDiv + '/input';
  }
  get clearDateIcon() {
    let path = '//span[contains(@class, "ux-datepicker__clear-date-icon")]';
    return this.datepickerDiv + path;
  }
  async isClearable() {
    return await (await $(this.dataE2e + '//div[contains(@class, "ux-datepicker__clear-date-wrapper")]')).isExisting();
  }
  get matDatepicker() {
    return this.datepickerDiv + '/mat-datepicker';
  }
  get datepickerButton() {
    return new CoUxButton(this.dataE2e);
  }
  async isReadOnly() {
    return await (await $(this.datepickerDiv + '//input[contains(@class,"ux-form-group__read-only")]')).isExisting();
  }
  async noButton() {
      let cl = await (await this.root.getChild('//input[contains(@class,"ux-datepicker--no-button")]')).isPresent();
      if (cl) {
          return true;
      } else if (!cl) {
          return false;
      } else {
          throw new Error('ux-datepicker component object needs to be revised');
      }
  }
  get overlayContainerCO() {
    return new CdkOverlayContainer('//body');
  }
  get matDatepicker() {
    return new MatDatepickerContent(this.overlayContainerCO.overlayPane);
  }
}


