import Component from '../../component.js'
import { elementAttributeContains } from '../../../core/utils.js'

export default class CoEuiInputText extends Component {
    constructor(parent) {
      let selector = 'input[@euiInputText]' ;
      super(parent, selector);
      // https://citnet.tech.ec.europa.eu/CITnet/stash/projects/CSDR/repos/eui/browse/packages/components-next/src/lib/components/eui-input-text/eui-input-text.component.ts
    }

    async isInvalid() {
      return await elementAttributeContains(this.currentPath, 'class', 'eui-input-text--invalid');
    }
    async isReadOnly() {
      return await (await $(this.currentPath + '/self::input[@readonly]')).isExisting();
    }
    async isDisabled() {
      return await elementAttributeContains(this.currentPath, 'class', 'eui-input-text--disabled');
    }

    async hasMaxLenght() {
      return await(await $(this.currentPath + '/self::input[@maxlength]')).isExisting();
    }
    async maxLenght() {
      let maxLenght = await (await $(this.currentPath)).getAttribute('maxlength');
      return maxLenght;
    }
    async maxLenghtIndicator() {
      if (await this.maxLenght()) {
        return this.currentPath + '/ancestor::*[1]//span[@class = "input-maxlength"]';
      }
    }

}


