import Component from '../component.js';
import CoEuiIconSvg from './eui-icon-svg.js';
import CoEuiInputText from './eui-input-text.js';
import CoEuiInputNumber from './eui-input-number.js';

export default class CoEuiTimepicker extends Component {
  constructor(parent) {
    let selector = 'eui-timepicker' ;
    super(parent, selector);
    //https://citnet.tech.ec.europa.eu/CITnet/stash/projects/CSDR/repos/eui/browse/packages/components/eui-timepicker/eui-timepicker.component.html?at=master
  }
  get timepicker() {
    return this.currentPath + '//div[contains(@class,"eui-timepicker")]';
  }
  async isDatetimepicker() {
    return await (await $(this.currentPath + '/self::*[contains(@class,"eui-timepicker--centered")]')).isExisting();
  }
  get inputTextCO(){
    return new CoEuiInputText(this.timepicker);
  }
  async isOneInputField(){
    return await(await this.inputTextCO.element()).isExisting();
  }
    //hour
  get hourInputContainer() {
    return this.timepicker + '//div[contains(@class, "eui-timepicker__input-container")][1]';
  }
  async isMultipleInputs() {
    return await(await $(this.hourInputContainer)).isExisting();
  }
  get hourIncreaseLink() {
    return this.hourInputContainer + '//div[contains(@class, "eui-timepicker__chevron")][1]';
  }
  async hourIsReadOnly(){
    return ! await(await $(this.hourIncreaseLink)).isExisting();
  }
  get hourIncreaseIconCO() {
    return new CoEuiIconSvg(this.hourIncreaseLink).byAttributeContains('icon', "eui-chevron-up");
  }
  get hourInputTextCO() {
    return new CoEuiInputNumber(this.hourInputContainer).byAttributeContains('class', "eui-timepicker__input");
  }
  async hourInputIsReadOnly(){
    return await (await $(this.hourInputTextCO.currentPath + '[@readonly]')).isExisting();
  }
  get hourDecreaseLink() {
    return this.hourInputContainer + '//div[contains(@class, "eui-timepicker__chevron")][2]';
  }
  get hourDecreaseIconCO() {
    return new CoEuiIconSvg(this.hourDecreaseLink).byAttributeContains('icon', "eui-chevron-down");
  }
  get hourMinuteSpacer() {
    return this.timepicker + '//div[contains(@class, "eui-timepicker__spacer")][1]';
  }
    //minutes
  get minutesInputContainer() {
    return this.timepicker + '//div[contains(@class, "eui-timepicker__input-container")][2]';
  }
  get minutesIncreaseChevronLink() {
    return this.minutesInputContainer + '//div[contains(@class, "eui-timepicker__chevron")][1]';
  }
  get minutesIncreaseChevronIconCO() {
    return new CoEuiIconSvg(this.minutesIncreaseChevronLink).byAttributeContains('icon', "eui-chevron-up");
  }
  get minutesInputCO() {
    return new CoEuiInputNumber(this.minutesInputContainer).byAttributeContains('class', "eui-timepicker__input");
  }
  async minutesInputIsReadOnly(){
    return await (await $(this.minutesInputCO.currentPath + '[@readonly]')).isExisting();
  }
  get minutesDecreaseLink() {
    return this.minutesInputContainer + '//div[contains(@class, "eui-timepicker__chevron")][2]';
  }
  get minutesDecreaseIconCO() {
    return new CoEuiIconSvg(this.minutesDecreaseLink).byAttributeContains('icon', "eui-chevron-down");
  }

  async hasSeconds() {
    let spacerState = await (await $(this.minutesSecondsSpacer)).isExisting();
    let secondsInputState = await (await $(this.secondsInputContainer)).isExisting();
    if(spacerState && secondsInputState) {
      return true;
    } else {
      return false;
    }
  }
  get minutesSecondsSpacer() {
    return this.timepicker + '//div[contains(@class, "eui-timepicker__spacer")][2]';
  }
  //seconds
  get secondsInputContainer() {
    return this.timepicker + '//div[contains(@class, "eui-timepicker__input-container")][3]';
  }
  get secondsIncreaseLink() {
    return this.secondsInputContainer + '//div[contains(@class, "eui-timepicker__chevron")][1]';
  }
  get secondsIncreaseIconCO() {
    return new CoEuiIconSvg(this.secondsIncreaseLink).byAttributeContains('icon', "eui-chevron-up");
  }
  get secondsInputCO() {
    return new CoEuiInputNumber(this.secondsInputContainer).byAttributeContains('class', "eui-timepicker__input");
  }
  async secondsInputIsReadOnly(){
    return await (await $(this.secondsInputCO.currentPath + '[@readonly]')).isExisting();
  }
  get secondsDecreaseLink() {
    return this.secondsInputContainer + '//div[contains(@class, "eui-timepicker__chevron")][2]';
  }
  get secondsDecreaseIconCO() {
    return new CoEuiIconSvg(this.secondsDecreaseLink).byAttributeContains('icon', "eui-chevron-down");
  }
}
