import Component  from '../component.js'

export default class CoUxFormGroup extends Component {
    constructor(parent) {
      let selector = 'ux-form-group';
      super(parent, selector);
    }
    get formGroupLabelWrapper() {
      let path = '//label[contains(@class,"ux-form-group__label-wrapper")]';
      return this.currentPath + path;
    }
    get formGroupLabel() {
      let path = '//span[contains(@class,"ux-form-group__label")]';
      return this.formGroupLabelWrapper + path;
    }
    async isRequired() {
      let cl = await (await $(this.currentPath + '//span[contains(@class,"ux-form-group__required-indicator")]')).isExisting();
      if (cl) {
         return true;
      } else if ( !cl ) {
         return false;
      } else {
         throw new Error('ux-form-group component object needs to be revised, ' +
         'is Required is missing a class');
      }
    }
    get infoLabel() {
      let path = '//span[contains(@class,"ux-form-group__info-label")]';
      return this.currentPath + path;
    }
    get inputContent() {
      let path = '//div[@class ="ux-form-group__input-content"]';
      return this.currentPath + path;
    }
    async  isReadOnly() {
      let cl = await (await $(this.inputContent + '//div[contains(@class,"ux-form-group__read-only")]')).isExisting();
      if (cl) {
         return true;
      } else if ( !cl ) {
         return false;
      } else {
         throw new Error('ux-form-group component object needs to be revised, ' +
         'is ReadOnly is missing a class');
      }
    }
    async isLoadingIndicatorActive() {
      let cl = await (await $(this.inputContent + '//span[contains(@class,"ux-form-group__loading-indicator")]')).isExisting();
      if (cl) {
         return true;
      } else if ( !cl ) {
         return false;
      } else {
         throw new Error('ux-form-group component object needs to be revised, ' +
         'is Loading Indicator Active is missing a class');
      }
    }
    labelByText(text) {
      let path = '//descendant-or-self::label[text()[normalize-space()="' + text + '"]]';
      return this.inputContent + path;
    }
    async hasValidationErrorMessage() {
      let cl = await (await $('//div[contains(@class,"ux-form-group__messages-wrapper")]')).getAttribute('data-e2e');
      if ( cl.includes('validationErrorMessage')) {
         return true;
      } else if ( !cl ) {
         return false;
      } else {
         throw new Error('ux-form-group component object needs to be revised, ' +
         'error message is missing a class');
      }
    }
    async isValid() {
      let validationErrorMessage = await (await this.feedback.element()).getAttribute('class');
      if ( validationErrorMessage.includes('ux-u-color-danger')) {
         return false;
      } else {
         return true;
      }
    }
    get customSubContentPlaceholder() {
      let path = '//div[contains(@class,"ux-form-group__messages-wrapper")]//*[@data-e2e = "ux-form-group-subContent"]';
      return this.currentPath + path;
    }
}


