import Component from '../../component.js'
import { elementAttributeContains } from '../../../core/utils.js'
import CoUxControlFeedback from './ux-control-feedback.js'

export default class CoUxFormGroup extends Component {
    constructor(parent) {
      let selector = 'ux-form-group';
      super(parent, selector);
      //https://citnet.tech.ec.europa.eu/CITnet/stash/projects/CSDR/repos/eui/browse/packages/components/src/lib/ux-components/ux-form-group/ux-form-group.component.html
    }
    get dataE2E() {
      let path = '//div[@data-e2e = "ux-form-group"]';
      return this.currentPath + path;
    }
    async hasDanger() {
      return await elementAttributeContains(this.dataE2E, 'class', 'has-danger');
    }
    get formGroupLabelWrapper() {
      let path = '//label[contains(@class,"ux-form-group__label-wrapper")]';
      return this.dataE2E + path;
    }
    async isVertical() {
      return await elementAttributeContains(this.formGroupLabelWrapper, 'class', 'form-control-label');
    }
    get formGroupLabel() {
      let path = '//span[contains(@class,"ux-form-group__label")]';
      return this.formGroupLabelWrapper + path;
    }
    get requiredIndicator() {
      let path = '//span[contains(@class,"ux-form-group__required-indicator")]';
      return this.dataE2E + path;
    }
    async isRequired() {
      return await (await $(this.requiredIndicator)).isExisting();
    }
    get infoLabel() {
      let path = '//span[contains(@class,"ux-form-group__info-label")]';
      return this.formGroupLabelWrapper + path;
    }
    async hasInfoLabel() {
      return await (await $(this.infoLabel)).isExisting();
    }
    async hasCursorHelp() {
      return await elementAttributeContains(this.infoLabel, 'class', 'ux-u-cursor-help');
    }
    get formGroupLeftTitleContentPlaceholder() {
      let path = '//uxFormGroupLeftTitleContent';
      return this.formGroupLabelWrapper + path;
    }
    get inputContent() {
      let path = '//div[contains(@class,"ux-form-group__input-content")]';
      return this.dataE2E + path;
    }
    // from feedbackTypeClass
    get controlFeedbackCO() {
      return new CoUxControlFeedback(this.inputContent);
    }
    async hasControlFeedback() {
      return await (await $(this.controlFeedbackCO.currentPath)).isExisting();
    }
    async isReadOnly() {
      return await elementAttributeContains(this.inputContent + '//div', 'class', 'ux-form-group--read-only');
    }
    get loadingIndicator() {
      let path = '//span[contains(@class,"ux-form-group__loading-indicator")]';
      return this.inputContent + path;
    }
    async isLoadingIndicatorActive() {
      return await (await $(this.loadingIndicator)).isExisting();
    }
    get validationErrorMessage() {
      let path = '//div[@data-e2e = "ux-form-group-validationErrorMessage"]';
      return this.currentPath + path;
    }
    async hasValidationErrorMessage() {
      return await (await $(this.validationErrorMessage)).isExisting();
    }
    get validationErrorMessageDiv() {
      let path = '//div';
      return this.validationErrorMessage + path;
    }
    get controlFeedbackErrorMessageCO() {
      return new CoUxControlFeedback(this.validationErrorMessageDiv);
    }
    async isValid() {
      return !(await(await $(this.controlFeedbackErrorMessageCO.currentPath)).isExisting());
    }
    async validationErrorFeedbackClass() {
      return await (await $(this.controlFeedbackErrorMessageCO)).getAttribute('typeclass');
    }
    get customSubContent() {
      let path = '//div[@data-e2e = "ux-form-group-subContent"]';
      return this.currentPath + path;
    }
    async hasCustomSubContent() {
      return await (await $(this.customSubContent)).isExisting();
    }
    get customSubContentPlaceholder() {
      let path = '//uxFormGroupSubContent';
      return this.customSubContent + path;
    }
    // from component.ts
    async hasRow() {
      return await elementAttributeContains(this.dataE2E, 'class', 'row');
    }
    async isInline() {
      return await elementAttributeContains(this.dataE2E, 'class', 'ux-form-group--inline');
    }
    async isVertical() {
      return await elementAttributeContains(this.dataE2E, 'class', 'ux-form-group--vertical');
    }
    async hasLabel() {
      return !(await elementAttributeContains(this.dataE2E, 'class', 'ux-form-group--no-label'));
    }
    async isCompact() {
      return await elementAttributeContains(this.dataE2E, 'class', 'ux-form-group--compact');
    }
    async isUltraCompact() {
      return await elementAttributeContains(this.dataE2E, 'class', 'ux-form-group--ultra-compact');
    }
}


