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

export default class CoUxFormControlSelect extends Component {
    constructor(parent) {
        let selector = 'select[@data-e2e = "ux-form-control-sel-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
    }
    getSelectOptionByIndex(index) {
        return '(' + this.currentPath + '//option' + ')[' + index + ']';
    }
    getOptionByValue(value) {
        let path = '//option[@value="' + value + '"]';
        return this.currentPath + path;
    }
    getOptionByText(text) {
        let path = '//option[contains(string(), "' + text + '")]';
        return this.currentPath + path;
    }
    async optionListHasGroups() {
        let cl = await (await $(this.currentPath + '//optgroup')).isExisting();
        if (cl) {
            return true;
        } else {
            return false;
        }
    }
    getGroupByIndex(index) {
        return '(' + this.currentPath + '//optgroup' + ')[' + index + ']';
    }
    getGroupOptionByIndex(gIndex, oIndex) {
        return '(' + this.getGroupByIndex(gIndex) + '//option'+ ')[' + oIndex + ']';
    }
    async isSelectDisabled() {
        let at = await (await $(this.currentPath)).getAttribute('Disabled');
        if ( at === 'true' ) {
            return true;
        } else if (at === null) {
            return false;
        } else { throw new Error(
            'ux-form-control <isSelectDisabled> method needs to be revised!');
        }
    }
}


