import Component from './component.js'

export default class SelectComponent extends Component {
    /**
    * Expects the parent element and an xpath selector (without the leading slashes)
    * @param parent WebdriverIO.Element
    */
    constructor(parent, selector) {
        if (selector) {
            super(parent, selector);
        } else {
            super(parent, 'select');
        }
    }
    /**
    * @param value string
    * @type WebdriverIO.Element
    */
    optionByValue(value) {
        let path = '//option[@value="' + value + '"]';
        return this.currentPath + path;
    }
    /**
    * @param text string
    * @type WebdriverIO.Element
    */
    optionByText(text) {
        let path = '//option[contains(string(), "' + text + '")]';
        return this.currentPath + path;
    }
    /**
    * @param index number
    * @type WebdriverIO.Element
    */
    optionByIndex(index) {
        let path = '//option[' + index + ']';
        return this.currentPath + path;
    }
    /**
    * Returns a list of select options
    * @type WebdriverIO.ElementArray
    */
    async optionsList() {
        let path = '//option';
        return await $$(this.currentPath + path);
    }
}
