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

export default class CoUxFormControlNumber extends Component {
    constructor(parent) {
        let selector = 'span[@data-e2e ="ux-form-control-num-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 numberInput() {
        let path = '//input[contains(@class, "ux-form-control")]';
        return this.currentPath + path;
    }
       /**
   * @param input type/uxcleave/id/placeholder/tabindex/aria-required/aria-invalid
   * @type string 
   */
    async isDisabled() {
        let at = await (await $(this.numberInput)).getAttribute('Disabled');
        if ( at === 'true' ) {
            return true;
        } else if (at === null) {
            return false;
        } else { throw new Error(
            '<CoUxFormControlNumber> <isDisabled> method needs to be revised!');
        }
    }
    async isReadOnly() {
        let at = await (await $(this.numberInput)).getAttribute('style');
        if ( at == 'display: block;' ) {
            return false;
        } else if (at == 'display: none;') {
            return true;
        } else { throw new Error(
            '<CoUxFormControlNumber> <isReadOnly> method needs to be revised!');
        }
    }
    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;
        }
    }
}


