import Component  from '../component.js';

export default class CoUxFormControlTextArea extends Component {
    constructor(parent) {
        let selector = 'span[@data-e2e ="ux-form-control-ta-rw"]';
        super(parent, selector);
        //https://citnet.tech.ec.europa.eu/CITnet/stash/projects/CSDR/repos/eui/browse/packages/core/src/lib/commons/ux-components/ux-form-control/ux-form-control.component.html?at=refs%2Fheads%2Fsupport%2F7.x
    }
    get textareaField() {
        let path = '//textarea[contains(@class, "ux-form-control")]';
        return this.currentPath + path;
    }
    async hasMaxLength() {
        let cl = awit (await $(this.currentPath + '/ancestor-or-self::ux-form-control[1]')).getAttribute('maxlength');
        if (cl != null ) {
            return true;
        } else {
            return false;
        }
    }
    async maxLength() {
        return await (await $(this.currentPath + '/ancestor-or-self::ux-form-control[1]')).getAttribute('maxlength');
    }
    get errorIndicator() {
        return this.currentPath + '//span[contains(@class, "input-maxlength")]';
    }
    async hasError() {
        let cl = await(await $(this.errorIndicator)).getAttribute('class');
        if (cl.includes('error')) {
            return true;
        } else {
            return false;
        }
    }
    async isTextAreaDisabled() {
        let at = await (await $(this.textareaField)).getAttribute('Disabled');
        if ( at === 'true' ) {
            return true;
        } else if (at === null) {
            return false;
        } else { throw new Error(
            'ux-form-control <isTextAreaDisabled> method needs to be revised!');
        }
    }
}


