import Component from '../../component.js';
import CoUxControlFeedback from './ux-control-feedback.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/components/src/lib/ux-components/ux-form-control/ux-form-control.component.html
    }
    get textareaField() {
        let path = '//textarea[contains(@class, "ux-form-control")]';
        return this.currentPath + path;
    }
    async hasMaxLength() {
        let cl = await (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 maxLengthIndicator() {
        let path = '//span[contains(@class, "input-maxlength")]';
        return this.currentPath + path;
    }
    get controlFeedbackCO() {
        return new CoUxControlFeedback(this.currentPath + '/ancestor-or-self::ux-form-control[1]');
    }
    async hasError() {
        return await (await $(this.controlFeedbackCO.currentPath)).isExisting();
    }

    async isDisabled() {
        let at = await(await $(this.textareaField)).getAttribute('Disabled');
        if ( at === 'true' ) {
            return true;
        } else if (at === null) {
            return false;
        } else { throw new Error(
            '<CoUxFormControlTextArea> <isDisabled> method needs to be revised!');
        }
    }
}


