import {PageConfigTypes} from "../../../custom-types/pageConfig-types";
import {browser, $, $$, expect} from '@wdio/globals'

/**
 * @param  selectionType - only accepts 'value' or 'text'
 * @param  value -> to select the option by value of the element
 * @param  dismiss -> to select the option by text
 */

export default async function (selectionType: string, data: string, pageConfig: PageConfigTypes) {
    if (selectionType.trim() !== 'value' && selectionType.trim() !== 'text')
        throw new Error(`Invalid selection for "selectOption" function. Valid selection is "value" OR "text"`);
    (selectionType === 'text') ? await $(pageConfig.selector).selectByVisibleText(data) : await $(pageConfig.selector).selectByAttribute(selectionType, data);

};
