package cz.moneta.test.dsl.monetaportal.components;

import cz.moneta.test.dsl.monetaportal.components.forms.AlaCarteLoanForm;
import cz.moneta.test.dsl.monetaportal.loans.GetCreditAccountPage;
import cz.moneta.test.dsl.monetaportal.more.ExpressBusinessWizard;
import cz.moneta.test.dsl.monetaportal.more.InternetBankPage;
import cz.moneta.test.dsl.monetaportal.more.SmartBankPage;
import cz.moneta.test.harness.context.StoreAccessor;
import cz.moneta.test.harness.endpoints.MonetaPortalEndpoint;
import cz.moneta.test.harness.support.web.Click;
import cz.moneta.test.harness.support.web.CustomAction;
import cz.moneta.test.harness.support.web.Until;
import cz.moneta.test.harness.support.web.Wait;

public interface Naviblocks extends StoreAccessor {

    //NAVIBLOCKS
    String NAVIBLOCKS_DIV = "//div[contains(@class,'page-section page-section--naviblocks page-section--naviblocks-big')]";
    String NAVIBLOCKS_W2C_BUTTON = NAVIBLOCKS_DIV + "//div[not(contains(@class, 'phone-visible'))]/a[contains(@class, 'w2c')]/..";
    String NAVIBLOCKS_W2B_BUTTON = NAVIBLOCKS_DIV + "//div[not(contains(@class, 'phone-visible'))]/a[contains(@class, 'w2b')]/..";
    String NAVIBLOCKS_ONLINE_NEW_CLIENTS = NAVIBLOCKS_DIV + "//h3[@class='naviblocks-tile__title phone-visible' and text()='Online pro nové klienty']/../div[@class= 'naviblocks-tile__link']";
    String NAVIBLOCKS_ONLINE_NEW_UDC = NAVIBLOCKS_DIV + "//h3[@class='naviblocks-tile__title phone-visible' and text()='Sjednání sloučení půjček online']/../div[@class= 'naviblocks-tile__link']";
    String NAVIBLOCKS_MERGE_IB_BUTTON = NAVIBLOCKS_DIV + "//h3[@class='naviblocks-tile__title']/span[contains(text(), 'Internet')]/../../div[@class= 'naviblocks-tile__link']";
    String NAVIBLOCKS_MERGE_SB_BUTTON = NAVIBLOCKS_DIV + "//div[not(contains(@class, 'phone-visible'))]/a[contains(@href, '/app')]";
    String NAVIBLOCKS_LOGIN_IB_BUTTON = NAVIBLOCKS_DIV + "//a[contains(text(), 'Internet')]/../../div[@class= 'naviblocks-tile__link']";
    String NAVIBLOCKS_IB_PAGE_BUTTON = NAVIBLOCKS_DIV + "//span[contains(text(), 'Internet')]/../../div[@class= 'naviblocks-tile__link']";
    String NAVIBLOCKS_ONLINE_BUSINESS_EXPRESS = NAVIBLOCKS_DIV + "//div[not(contains(@class, 'phone-visible'))]/a[contains(@href, 'expres-business')]";
    String NAVIBLOCKS_ONLINE_CREDIT_ACCOUNT_BUTTON = NAVIBLOCKS_DIV + "//div[not(contains(@class, 'phone-visible'))]/a[contains(@href, '/pujcky-a-uvery/ziskat-kreditni-ucet')]";
    String NAVIBLOCKS_W2C_LINK = NAVIBLOCKS_DIV + "//a[@class='w2c-modal']";
    String NAVIBLOCKS_BUILDING_SAVINGS_ONLINE_NEW_CLIENTS = NAVIBLOCKS_DIV + "//h3[@class='naviblocks-tile__title phone-visible' and text()='Sjednání online']/../div[@class= 'naviblocks-tile__link']";
    String NAVIBLOCKS_CURRENT_ACCOUNT_ONLINE_NEW_CLIENTS = NAVIBLOCKS_DIV + "//h3[@class='naviblocks-tile__title']//span[contains(text(), 'Plně online')]/../../div[@class= 'naviblocks-tile__link']";
    String NAVIBLOCKS_SAVING_ACCOUNT_ONLINE_NEW_CLIENTS = NAVIBLOCKS_DIV + "//h3[@class='naviblocks-tile__title']/span[contains(text(), 'běžným účtem')]/../../div[@class= 'naviblocks-tile__link']";
    String NAVIBLOCKS_INVEST_ONLINE = NAVIBLOCKS_DIV + "//h3[@class='naviblocks-tile__title phone-visible' and text()='Investujte online']/../div[@class= 'naviblocks-tile__link']";
    String W2B_DIV = "//div[@id='W2bModal']";
    String W2B_SEARCH_BRANCH_INPUT = W2B_DIV + "//input[@id = 'searchBranchInput']";

    //NAVIBLOCKS
    @Click(value = NAVIBLOCKS_W2C_BUTTON, andWait = @Wait(explicitWaitSeconds = 1))
    Web2Call clickNaviblocksW2C();

    @Click(value = NAVIBLOCKS_W2B_BUTTON, andWait = @Wait(value = W2B_SEARCH_BRANCH_INPUT, until = Until.VISIBLE))
    Web2Branch clickNaviblocksW2B();

    @CustomAction
    default AlaCarteLoanForm clickNaviblocksCreateNewClientsOnline() {
        MonetaPortalEndpoint endpoint = getEndpoint(MonetaPortalEndpoint.class);
        endpoint.click(() -> NAVIBLOCKS_ONLINE_NEW_CLIENTS);
        endpoint.focusToNewPopup(20);
        endpoint.maximizeBrowserWindow();
        return null;
    }

    @CustomAction
    default AlaCarteLoanForm clickNaviblocksCreateUDCOnline() {
        MonetaPortalEndpoint endpoint = getEndpoint(MonetaPortalEndpoint.class);
        endpoint.click(() -> NAVIBLOCKS_ONLINE_NEW_UDC);
        endpoint.focusToNewPopup(20);
        endpoint.maximizeBrowserWindow();
        return null;
    }

    @CustomAction
    default InternetBankPage openNaviblocksIB() {
        MonetaPortalEndpoint endpoint = getEndpoint(MonetaPortalEndpoint.class);
        endpoint.click(() -> NAVIBLOCKS_MERGE_IB_BUTTON);
        endpoint.focusToNewPopup(20);
        endpoint.maximizeBrowserWindow();
        return null;
    }

    @CustomAction
    default SmartBankPage openNaviblocksSB() {
        MonetaPortalEndpoint endpoint = getEndpoint(MonetaPortalEndpoint.class);
        endpoint.click(() -> NAVIBLOCKS_MERGE_SB_BUTTON);
        endpoint.focusToNewPopup(20);
        endpoint.maximizeBrowserWindow();
        return null;
    }

    @Click(value = NAVIBLOCKS_IB_PAGE_BUTTON, andWait = @Wait(explicitWaitSeconds = 1))
    InternetBankPage openNaviblocksOpenInternetBanking();

    @CustomAction
    default InternetBankPage openNaviblocksOpenIB() {
        MonetaPortalEndpoint endpoint = getEndpoint(MonetaPortalEndpoint.class);
        endpoint.click(() -> NAVIBLOCKS_LOGIN_IB_BUTTON);
        endpoint.focusToNewPopup(20);
        endpoint.maximizeBrowserWindow();
        return null;
    }

    @Click(value = NAVIBLOCKS_ONLINE_BUSINESS_EXPRESS, andWait = @Wait(explicitWaitSeconds = 1))
    ExpressBusinessWizard clickNaviblocksCreateBusinessExpressOnline();

    @Click(value = NAVIBLOCKS_W2C_LINK, andWait = @Wait(explicitWaitSeconds = 1))
    Web2Call clickNaviblocksW2CLink();

    @Click(NAVIBLOCKS_ONLINE_CREDIT_ACCOUNT_BUTTON)
    GetCreditAccountPage clickNaviblocksCreditAccountButton();

    @CustomAction
    default AlaCarteLoanForm clickNaviblocksBuildingSavingsCreateNewClientsOnline() {
        MonetaPortalEndpoint endpoint = getEndpoint(MonetaPortalEndpoint.class);
        endpoint.click(() -> NAVIBLOCKS_BUILDING_SAVINGS_ONLINE_NEW_CLIENTS);
        endpoint.focusToNewPopup(20);
        endpoint.maximizeBrowserWindow();
        return null;
    }

    @CustomAction
    default AlaCarteLoanForm clickNaviblocksCurrentAccountCreateNewClientsOnline() {
        MonetaPortalEndpoint endpoint = getEndpoint(MonetaPortalEndpoint.class);
        endpoint.click(() -> NAVIBLOCKS_CURRENT_ACCOUNT_ONLINE_NEW_CLIENTS);
        endpoint.focusToNewPopup(20);
        endpoint.maximizeBrowserWindow();
        return null;
    }

    @CustomAction
    default AlaCarteLoanForm clickNaviblocksSavingAccountCreateNewClientsOnline() {
        MonetaPortalEndpoint endpoint = getEndpoint(MonetaPortalEndpoint.class);
        endpoint.click(() -> NAVIBLOCKS_SAVING_ACCOUNT_ONLINE_NEW_CLIENTS);
        endpoint.focusToNewPopup(20);
        endpoint.maximizeBrowserWindow();
        return null;
    }

    @CustomAction
    default AlaCarteLoanForm clickNaviblocksInvestOnline() {
        MonetaPortalEndpoint endpoint = getEndpoint(MonetaPortalEndpoint.class);
        endpoint.click(() -> NAVIBLOCKS_INVEST_ONLINE);
        endpoint.focusToNewPopup(20);
        endpoint.maximizeBrowserWindow();
        return null;
    }
}