/**
 * This function requires the module {@link module../pages/eui/10x/ux/landing-10x.po.js}.
  * @requires ../pages/eui/10x/ux/landing-10x.po.js
 */
import EuiLandingPage from '../pages/eui/10x/ux/landing-10x.po.js'

 /**
   * This function checks if cookie banner is displayed.
   * Clicks on accept or refuse link according accept param.
   * Check if cookie banner is not displayed.
   * @async
   * @param {boolean} accept - If true accept link is clicked
   */

export async function cookieBanner(accept) {
    let landingPage = new EuiLandingPage();
    let cookieBanner = await $(landingPage.cookieBanner);
    let button;

    if (accept) {
        button = await $(landingPage.cookieBannerAcceptLink);
    } else {
        button = await $(landingPage.cookieBannerRefuseLink);
    }
    let cookieWindow = await cookieBanner.isDisplayed();

    if (cookieWindow) {
        await button.click();
        await cookieBanner.waitForDisplayed({timeout:3000, reverse:true, timeoutMsg:'Cookie Banner still visible', interval:100});
    }
}
