package cz.moneta.test.dsl.monetaportal;

import cz.moneta.test.dsl.monetaportal.components.MainMenu;
import cz.moneta.test.dsl.monetaportal.components.NavigationBar;
import cz.moneta.test.dsl.monetaportal.components.Web2Branch;
import cz.moneta.test.dsl.monetaportal.components.Web2Call;
import cz.moneta.test.dsl.monetaportal.more.*;
import cz.moneta.test.harness.context.StoreAccessor;
import cz.moneta.test.harness.endpoints.MonetaPortalEndpoint;
import cz.moneta.test.harness.support.web.*;

import static cz.moneta.test.dsl.monetaportal.HomePage.HOMEPAGE_EXCHANGE_RATES_TABLE;

@Wait(HOMEPAGE_EXCHANGE_RATES_TABLE)
public interface HomePage extends WebFlow<HomePage>, MainMenu, NavigationBar, StoreAccessor {

    //Homepage
    String HOMEPAGE_ACCEPT_COOKIES_BUTTON = "//button[@id = 'onetrust-accept-btn-handler']";
    String HOMEPAGE_BRANCHES_LINK = "//div[contains(@class, 'f-numerical-benefits__holder')]//a[@href='/kontakt/pobocky-moneta-money-bank']";
    String HOMEPAGE_ATM_LINK = "//div[contains(@class, 'f-numerical-benefits__holder')]//a[@href='/kontakt/bankomaty-moneta-money-bank#mapa-section']";
    String HOMEPAGE_ONLINE_PRODUCTS_LINK = "//div[contains(@class, 'f-numerical-benefits__holder')]//a[@href='/online/sjednani-produktu']";
    String HOMEPAGE_W2C_LINK = "//a[@class='f-contact-bar-item homepageW2C']";
    String HOMEPAGE_W2B_LINK = "//a[@class='f-contact-bar-item w2b']";
    String HOMEPAGE_ONLINE_SUPPORT_LINK = "//a[@class='f-contact-bar-item ' and @href='/online']";
    String HOMEPAGE_EXCHANGE_RATES_LINK = "//a[@class='f-contact-bar-item ' and @href='/kurzovni-listek']";
    String HOMEPAGE_EXCHANGE_RATES_TABLE = "//section[contains(@id, 'portlet_ExchangeRatesTable_')]";
    String HOMEPAGE_EXCHANGE_RATES_TABLE_MORE_BUTTON = "//section[contains(@id, 'portlet_ExchangeRatesTable_INSTANCE_')]//span[@data-message-id='FilterTabs.moreCurrencies']";
    String HOMEPAGE_EN_PAGE = "//div[@class='links_right']//a[@href='https://ppe.moneta.cz/web/en']";

    @Click(HOMEPAGE_ACCEPT_COOKIES_BUTTON)
    HomePage clickAcceptCookies();

    @Click(HOMEPAGE_BRANCHES_LINK)
    BranchesPage clickHomePageBranches();

    @Click(HOMEPAGE_ATM_LINK)
    ATMsPage clickHomePageATMs();

    @Click(HOMEPAGE_ONLINE_PRODUCTS_LINK)
    OnlineProductPage clickOnlineProducts();

    @Click(HOMEPAGE_W2C_LINK)
    Web2Call clickHomePageW2C();

    @Click(HOMEPAGE_W2B_LINK)
    Web2Branch clickHomePageW2B();

    @Click(HOMEPAGE_ONLINE_SUPPORT_LINK)
    OnlineSupportPage clickOnlineSupport();

    @Click(HOMEPAGE_EXCHANGE_RATES_LINK)
    ExchangeRatesPage clickExchangeRates();

    @CheckElementPresent(HOMEPAGE_EXCHANGE_RATES_TABLE)
    HomePage checkHomePageExchangeRatesTable();

    @Click(HOMEPAGE_EXCHANGE_RATES_TABLE_MORE_BUTTON)
    ExchangeRatesPage clickExchangeRatesTableMore();

    @Click(HOMEPAGE_EN_PAGE)
    HomePageEN clickENPage();

    /**
     * Clicking on accept cookies button. This condition is here because tab with accept cookies
     * is showing up only on local computer, not on server.
     * @return
     */
    @CustomAction
    default HomePage acceptCookies() {
        MonetaPortalEndpoint endpoint = getEndpoint(MonetaPortalEndpoint.class);

        if (endpoint.isElementPresent(HOMEPAGE_ACCEPT_COOKIES_BUTTON, Lookup.XPATH)) {
            endpoint.click(() -> HOMEPAGE_ACCEPT_COOKIES_BUTTON);
        }
        return null;
    }
}