import Component from '../../component.js'
import CoUxButton from './ux-button.js'
import CdkOverlayContainer from '../../cdk-overlay-container.js'
import MatDatepickerContent from '../../material/mat-datepicker-content.js'
import InputComponent from '../../input.js'
import { elementAttributeContains } from '../../../core/utils.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/components/src/lib/ux-components/ux-datepicker/ux-datepicker.component.html
  }
  get dataE2E() {
    let path = '//div[@data-e2e = "ux-datepicker"]';
    return this.currentPath + path;
  }
  get dateWrapper() {
    return this.dataE2E + '//div[contains(@class, "ux-datepicker__date-wrapper")]';
  }
  get inputWrapper() {
    return this.dateWrapper + '//div[contains(@class, "ux-datepicker__input-wrapper")]';
  }
  get input() {
    return new InputComponent(this.inputWrapper);
  }
  async isInputReadOnly() {
    return await elementAttributeContains(this.input.currentPath, 'class', 'ux-datepicker--read-only');
  }
  async inputDateFormat() {
    return await (await( await this.input.element())).getAttribute('data-placeholder');
  }
  get spanClearable() {
    return this.inputWrapper + '//span[contains(@class, "eui-clearable-input-wrapper__clear")]';
  }
  async isInputClearable() {
    return await (await $(this.spanClearable)).isExisting();
  }
  get datepickerBtnCo() {
    return new CoUxButton(this.dateWrapper);
  }
  async isButtonDisabled() {
    return (await (await $(this.datepickerBtnCo.button)).getAttribute('disabled') != null);
  }
  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 datepickerButton() {
    return new CoUxButton(this.dataE2E);
  }
  async isReadOnly() {
    return await (await $(this.datepickerDiv + '//input[contains(@class,"ux-form-group__read-only")]')).isExisting();
  }
  async noButton() {
    return await (await $(this.inputWrapper + '//input[contains(@class,"ux-datepicker--no-button")]')).isExisting();
  }
  async isDisabled() {
    return await (await $(this.inputWrapper + '//input[contains(@class, "ux-datepicker--disabled")]')).isExisting();
  }
  get overlayContainerCO() {
    return new CdkOverlayContainer('//body');
  }
  get matDatepicker() {
    return new MatDatepickerContent(this.overlayContainerCO.overlayPane);
  }
}


