/**
 * This function requires the module {@link module../pages/eui/10x/eui-base.po.js}.
  * @requires ../pages/eui/10x/eui-base.po.js
 */
import EuiBasePage from '../pages/eui/10x/eui-base.po.js'
/**
   * This function checks language selector value and set it to lang param if values are different
   * @async
   * @param {string} lang - EN/FR
   */
export default async function languageSelector(lang) {
    lang = lang.toLowerCase();
    let euiBasePage = new EuiBasePage();

    let languageSel = await $(euiBasePage.languageSelector);
    let languageInd = await $(euiBasePage.languageIndicator);
    let languageSelLink = await $(euiBasePage.languageSelectorLink);
    // Check if language selector is displayed.
    await languageSel.waitForDisplayed({timeout:3000, timeoutMsg:'Language Selector is not present in main page', interval:100});
    let language = (await languageInd.getText()).toLowerCase();
    // If language indicator text value and lang parameter value are different, set selector language to lang param value.
    if (language !== lang ) {
        await languageSelLink.click();
        let languageSelButton = await $(euiBasePage.getLangSelButtonByText(lang));
        await languageSelButton.click();
    }
    // Check language indicator text value to have param value.
    await global.chaiExpect(await languageInd.getText()).to.contain(lang.toUpperCase());
}
