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

import cz.moneta.test.dsl.newib.NewIbPageFlow;
import cz.moneta.test.dsl.newib.authentification.AuthMobileKey;
import cz.moneta.test.dsl.newib.components.VerticalMainMenu;
import cz.moneta.test.harness.context.StoreAccessor;
import cz.moneta.test.harness.endpoints.ib.NewIbEndpoint;
import cz.moneta.test.harness.support.web.*;

import static cz.moneta.test.dsl.newib.mainpage.CardsPage.CARDS_XPATH;
import static org.junit.jupiter.api.Assertions.assertTrue;

@Wait(value = CARDS_XPATH, by = Lookup.XPATH, waitSecondsForElement = 60)
public interface CardsPage extends NewIbPageFlow<CardsPage>, StoreAccessor, VerticalMainMenu {
    String CARDS_XPATH = "//h1[@class='t-title t-title--h5 u-ml--small'][text()='Karty']";
    String SMART_CREDIT_CARD_BANNER_XPATH = "//div[@data-testid='banner-smart']";
    String CARD_NUMBER_XPATH = "//*[text()[contains(.,'%s')]]";
    String CARD_ACCOUNT_XPATH = "//*[text()[contains(.,'č.ú: %s/0600')]]";
    String DETAIL_AND_SETTINGS_BUTTON = "//span[@data-testid='detail-tab']";
    String SHOW_PIN_ON_CARD_BUTTON = "//button[text()='Zobrazit PIN na kartě']";
    String SHOW_PIN_BUTTON = "//button[@data-testid='show-pin']";
    String MOBILE_KEY_INPUT = "//label[text()='Mobilní klíč']/following::input[@id='mobileKey']";
    String CONTINUE = "//button[@data-testid='secondFactorSend']";
    String PIN_XPATH = "//img[@alt='PIN']";
    String SEND_SMS_BUTTON = "//button[@class='c-link c-link--small u-mr--medium' and text()='Potvrdit přes mobilní klíč']";
    String SELECT_CARD_XPATH = "//p[@data-testid='TextComponent']//*[text()[contains(., '%s')]]";
    String BLOCK_CANCEL_CARD_BTN_XPATH = "//button[text()='Zablokovat / zrušit kartu']";
    String BLOCK_CANCEL_DETAIL_XPATH = "//h1[text()='Blokace karty online']";
    String BLOCK_CARD_XPATH = "//li[@id='type_value-BLOCK']";
    String RENEWAL_CARD_XPATH = "//li[@id='type_value-RENEWAL']";
    String CANCEL_CARD_XPATH = "//li[@id='type_value-CANCEL']";
    String UNBLOCK_CARD_XPATH = "//li[@id='type_value-UNBLOCK']";
    String CONTINUE_BTN_XPATH = "//button[@data-testid='cardBlockSelectionNext']";
    String BLOCK_MESSAGE_XPATH = "//h2[text()[contains(.,'Kartu udržíme pod zámkem do')]]";
    String UNBLOCK_MESSAGE_XPATH = "//h2[text()[contains(., 'Karta je znovu aktivní')]]";
    String CANCEL_MESSAGE_XPATH = "//h2[text()[contains(., 'Kartu jsme zablokovali a zrušili')]]";
    String BACK_TO_CARD_BUTTON_XPATH = "//button[@data-testid='card-block-victoryNext']";
    String DETAIL_SETTINGS_BUTTON_XPATH = "//span[@data-testid='detail-tab']";
    String CARD_DETAIL_INFO_XPATH = "//small[text()[contains(., '%s')]]";
    String DEBIT_CARD_SELECT_XPATH = "//p[@data-testid='TextComponent']//small[text()[contains(.,'Debetní karty k účtu') or contains(., 'Business') or contains(., 'Standard')]]";
    String CARD_SUBMENU_XPATH = "//ul[@data-testid=\"SubMenu\"]";
    String LOADER_IMG_XPATH = "//*[@class='c-loader__image']";
    String DEBIT_CARD_ONBOARDING_NOT_VISIBLE_XPATH = "//div[not(.//div[@data-testid='banner-second-debit-card'])]";

    @CustomAction
    default CardsPage checkUrl() {
        NewIbEndpoint newIbEndpoint = getEndpoint(NewIbEndpoint.class);
        String actualUrl = newIbEndpoint.getCurrentUrl();
        String urlContains = "cards";
        assertTrue(actualUrl.contains(urlContains));
        return null;
    }

    @CheckElementPresent(SMART_CREDIT_CARD_BANNER_XPATH)
    CardsPage checkSmartCreditCardBannerIsPresent();

    @Wait(value = CARD_NUMBER_XPATH, isStringDynamicXpath = true)
    @Click(value = CARD_NUMBER_XPATH, isStringDynamicXpath = true)
    CardsPage clickCardNumber(String cardNumber);

    @Click(value = CARD_ACCOUNT_XPATH, isStringDynamicXpath = true)
    CardsPage clickAccountNumber(String accountNumber);

    @Click(DETAIL_AND_SETTINGS_BUTTON)
    CardsPage clickNextSettings();

    @Click(SHOW_PIN_ON_CARD_BUTTON)
    CardsPage clickShowPin();

    @Click(SHOW_PIN_BUTTON)
    CardsPage clickShowPinButton();

    @Wait(SEND_SMS_BUTTON)
    @Click(SEND_SMS_BUTTON)
    CardsPage clickSendSmsToAuth();

    @TypeInto(MOBILE_KEY_INPUT)
    CardsPage typeMobileKey(String mobileCode);

    @Click(value = CONTINUE, andWait = @Wait(value = PIN_XPATH, waitSecondsForElement = 100))
    CardsPage clickToShowPinAndWait();

    @Click(value = SELECT_CARD_XPATH, andWait = @Wait(value = BLOCK_CANCEL_CARD_BTN_XPATH, waitSecondsForElement = 100), isStringDynamicXpath = true)
    CardsPage selectCard(String maskedCardNumber);

    @Click(value = BLOCK_CANCEL_CARD_BTN_XPATH, andWait = @Wait(value = BLOCK_CANCEL_DETAIL_XPATH, waitSecondsForElement = 100))
    CardsPage clickOnBlockCancelCard();

    @Click(BLOCK_CARD_XPATH)
    CardsPage clickBlockCardRadio();

    @Click(RENEWAL_CARD_XPATH)
    CardsPage clickRenewalCardRadio();

    @Click(CANCEL_CARD_XPATH)
    CardsPage clickCancelCardRadio();

    @Click(UNBLOCK_CARD_XPATH)
    CardsPage clickUnblockCardRadio();

    @Click(CONTINUE_BTN_XPATH)
    AuthMobileKey clickContinue();

    @CheckElementPresent(value = BLOCK_MESSAGE_XPATH)
    CardsPage blockMessageAppeared();

    @CheckElementPresent(value = UNBLOCK_MESSAGE_XPATH)
    CardsPage unblockMessageAppeared();

    @CheckElementPresent(value = CANCEL_MESSAGE_XPATH)
    CardsPage cancelMessageAppeared();

    @Click(value = BACK_TO_CARD_BUTTON_XPATH, andWait = @Wait(value = LOADER_IMG_XPATH, until = Until.GONE, waitSecondsForElement = 50))
    CardsPage clickBackToCard();

    @Click(value = DETAIL_SETTINGS_BUTTON_XPATH, andWait = @Wait(value = LOADER_IMG_XPATH, until = Until.GONE, waitSecondsForElement = 50))
    CardsPage clickDetailsAndSettings();

    @CheckElementPresent(value = CARD_DETAIL_INFO_XPATH, by = Lookup.XPATH, isStringDynamicXpath = true)
    CardsPage checkCardDetailInfo(String cardDetailInfoMessage);

    @Click(value = DEBIT_CARD_SELECT_XPATH, andWait = @Wait(value = CARD_SUBMENU_XPATH, waitSecondsForElement = 50))
    CardsPage openCardsSubMenu();

    @CheckElementPresent(DEBIT_CARD_ONBOARDING_NOT_VISIBLE_XPATH)
    CardsPage checkNewDebitCardNotVisible();
}
