package cz.moneta.test.dsl.newib.mainpage;

import cz.moneta.test.dsl.newib.NewIbPageFlow;
import cz.moneta.test.dsl.newib.authentification.LoginPage;
import cz.moneta.test.harness.endpoints.ib.NewIbEndpoint;
import cz.moneta.test.harness.support.web.*;

import static cz.moneta.test.dsl.newib.mainpage.SuccessfullyLogoutPage.*;

@Wait({MAIN_MENU_LIST, LOGIN_ALERT_BANNER})
public interface SuccessfullyLogoutPage extends NewIbPageFlow<SuccessfullyLogoutPage> {
    String LOGIN_ALERT_BANNER = "//div[@data-testid='loginAlertBanner']";
    String MAIN_MENU_LIST = "//ul[@data-testid='MenuList']";
    String LOGOUT_PAGE_TEXT = "//h1[contains(text(),'Byli jste úspěšně odhlášeni.')]";
    String LOGOUT_PAGE_SESSION_TIMEOUT_TEXT = "//h1[contains(text(),'Dlouho se nic nedělo. Kvůli bezpečnosti jsme Vás odhlásili.')]";
    String CLOSE_COOKIES_PANEL = "//button[@id='onetrust-accept-btn-handler']";
    String BACK_TO_LOGIN_XPATH = "//button[@data-testid='backToLogin']";

    @CheckElementPresent(LOGOUT_PAGE_TEXT)
    SuccessfullyLogoutPage checkLogoutText();

    @CheckElementPresent(LOGOUT_PAGE_SESSION_TIMEOUT_TEXT)
    SuccessfullyLogoutPage checkLogoutSessionTimeoutText();

    @CustomAction
    default SuccessfullyLogoutPage closeCookiesPanelIfVisible() {
        NewIbEndpoint newIbEndpoint = getEndpoint(NewIbEndpoint.class);
        if (newIbEndpoint.isElementVisible(5, CLOSE_COOKIES_PANEL, Lookup.XPATH)) {
            newIbEndpoint.click(() -> CLOSE_COOKIES_PANEL);
        }
        return null;
    }

    @Click(BACK_TO_LOGIN_XPATH)
    LoginPage clickOnBackToLogin();
}
