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

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

import static cz.moneta.test.dsl.newib.savings.PrecontractPage.PRE_CONTRACTUAL_INFORMATION_TITLE_XPATH;

@Wait(value = {PRE_CONTRACTUAL_INFORMATION_TITLE_XPATH}, waitSecondsForElement = 30)
public interface PrecontractPage extends NewIbPageFlow<PrecontractPage> {

    String PRE_CONTRACTUAL_INFORMATION_TITLE_XPATH = "//h2[@class='t-title t-title--h4'][text()='Přečtěte si Předsmluvní informace']";
    String TITLE_BUILDING_SAVINGS_XPATH = "//h1[@class='t-title t-title--h3 u-mb--xLarge'][text()='Stavební spoření']";
    String AGREEMENT_CHECKBOX_XPATH = "//span[@class='f-checkbox__over']";
    String DECLINE_BUTTON_XPATH = "//button[@data-testid='decline'][text()='Nesouhlasím']";
    String GO_NEXT_BUTTON_XPATH = "//button[@data-testid='goNext'][text()='Souhlasím, pokračovat']";
    String AGREEMENT_TEXT_XPATH = "//span[@id='text-agreementCheckbox']//b[contains(text(), 'Prohlašuji, že jsem se seznámil s těmito dokumenty')]";
    String CONTRACT_TITLE_XPATH = "//h2[@class='t-title t-title--h4'][text()='Přečtěte si smlouvu s parametry produktu']";

    @CheckElementPresent(PRE_CONTRACTUAL_INFORMATION_TITLE_XPATH)
    PrecontractPage checkPreContractualInformationTitle();

    @CheckElementPresent(TITLE_BUILDING_SAVINGS_XPATH)
    PrecontractPage checkTitleBuildingSavings();

    @Click(AGREEMENT_CHECKBOX_XPATH)
    PrecontractPage clickOnAgreementCheckbox();

    @CheckElementPresent(DECLINE_BUTTON_XPATH)
    PrecontractPage checkDeclineButton();

    @CheckElementPresent(AGREEMENT_TEXT_XPATH)
    PrecontractPage checkAgreementText();

    @Click(value = GO_NEXT_BUTTON_XPATH, andWait = @Wait(value = CONTRACT_TITLE_XPATH, waitSecondsForElement = 30))
    ContractPage clickGoNextButton();

    @CustomAction
    default PrecontractPage scrollToBottom() {
        NewIbEndpoint ep = getEndpoint(NewIbEndpoint.class);
        ep.scrollIntoView(AGREEMENT_CHECKBOX_XPATH);
        return null;
    }
}