package cz.moneta.test.dsl.newib.settings.mobileapplication;

import cz.moneta.test.dsl.newib.NewIbPageFlow;
import cz.moneta.test.dsl.newib.components.HorizontalMainMenu;
import cz.moneta.test.dsl.newib.settings.SettingsModalPage;
import cz.moneta.test.harness.endpoints.ib.NewIbEndpoint;
import cz.moneta.test.harness.support.web.CheckElementPresent;
import cz.moneta.test.harness.support.web.Click;
import cz.moneta.test.harness.support.web.CustomAction;

import static org.junit.jupiter.api.Assertions.assertTrue;

public interface AboutTheSmartBankaPage extends NewIbPageFlow<SettingsModalPage>, HorizontalMainMenu {

    String BACK_TO_SETTINGS_BTN_XPATH = "//button[@data-testid='back-to-settings-crossroad']";
    String ACTIVATE_UP_BTN_XPATH = "//button[@data-testid='activate-mobile-app-button'][@class='c-btn c-btn--small']";
    String ACTIVATE_DOWN_BTN_XPATH = "//button[@data-testid='activate-mobile-app-button'][@class='c-btn']";
    String MORE_INFORMATION_BTN_XPATH = "//a[@data-testid='more-info-button']";
    String REDIRECTING_TO_OLD_IB_TITLE = "//h2[@class='t-title t-title--h3 c-modal__title'][text()='Přesměrujeme Vás do původní Internet Banky']";
    String DECLINE_REDIRECT_BTN_XPATH = "//button[@data-testid='decline-redirect-button']";
    String MOBILE_APP_TITLE_XPATH = "//h2[@class='t-title t-title--h3'][text()='Mobilní aplikace']";
    String SETTINGS_TITLE_XPATH = "//h2[@class='t-title t-title--h3 u-mb--0'][text()='Nastavení']";
    String CLOSE_BTN_XPATH = "//button[@data-testid='settings_modal-close']";


    @CustomAction
    default AboutTheSmartBankaPage checkUrl() {
        NewIbEndpoint newIbEndpoint = getEndpoint(NewIbEndpoint.class);
        String actualUrl = newIbEndpoint.getCurrentUrl();
        String urlContains = "settings/mobile-app";
        assertTrue(actualUrl.contains(urlContains));
        return null;
    }

    @CheckElementPresent(BACK_TO_SETTINGS_BTN_XPATH)
    AboutTheSmartBankaPage checkBackToSettingsIsPresent();

    @CheckElementPresent(ACTIVATE_UP_BTN_XPATH)
    AboutTheSmartBankaPage checkActivateUpIsPresent();

    @CheckElementPresent(ACTIVATE_DOWN_BTN_XPATH)
    AboutTheSmartBankaPage checkActivateDownIsPresent();

    @CheckElementPresent(MORE_INFORMATION_BTN_XPATH)
    AboutTheSmartBankaPage checkMoreInformationIsPresent();

    @Click(ACTIVATE_UP_BTN_XPATH)
    AboutTheSmartBankaPage clickOnActivateUp();

    @CheckElementPresent(REDIRECTING_TO_OLD_IB_TITLE)
    AboutTheSmartBankaPage checkRedirectingToOldIbTitleIsPresent();

    @Click(DECLINE_REDIRECT_BTN_XPATH)
    AboutTheSmartBankaPage clickOnCancel();

    @Click(ACTIVATE_DOWN_BTN_XPATH)
    AboutTheSmartBankaPage clickOnActivateDown();

    @CheckElementPresent(MOBILE_APP_TITLE_XPATH)
    AboutTheSmartBankaPage checkTitleIsPresent();

    @Click(BACK_TO_SETTINGS_BTN_XPATH)
    AboutTheSmartBankaPage clickOnBackToSetting();

    @CheckElementPresent(SETTINGS_TITLE_XPATH)
    SettingsModalPage checkSettingsTitleIsPresent();

    @Click(CLOSE_BTN_XPATH)
    AboutTheSmartBankaPage clickOnClose();

    @CustomAction
    default HorizontalMainMenu goToMoreInformationsAndCheckUrl() {
        NewIbEndpoint newIbEndpoint = getEndpoint(NewIbEndpoint.class);
        newIbEndpoint.click(() -> MORE_INFORMATION_BTN_XPATH);
        newIbEndpoint.switchToOtherWindow(5,2);
        String actualUrl = newIbEndpoint.getCurrentUrl();
        String urlContains = "smartbanka.moneta";
        assertTrue(actualUrl.contains(urlContains));
        return null;
    }
}
