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

export default class CoUxFormControlRadio extends Component {
    constructor(parent) {
        let selector = 'input[@data-e2e = "ux-form-control-ra-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 radioLabel() {
        let path = '/ancestor-or-self::ux-form-control[1]//label[contains(@class, "radio-label")]';
        return this.currentPath + path;
    }
    getRadioButtonLabelByText(text) {
        let path = '//descendant-or-self::*[text()[normalize-space()="' + text + '"]]';
        return this.radioLabel + path;
    }
    /**
    * @param input type/id/name/value/tabindex/aria-required/aria-invalid
    * @type string
    */
    async getInputAtribute(input) {
        let value = await (await $(this.currentPath)).getAttribute(input);
        return value;
    }
    async isRadioButtonDisabled() {
        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 <isRadioButtonDisabled> method needs to be revised!');
        }
    }
}


