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

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.mainpage.SigningModalPage.PAGE_LABEL_XPATH;
import static cz.moneta.test.dsl.newib.mainpage.SigningModalPage.PAGE_MODAL_SECTION_XPATH;
import static cz.moneta.test.dsl.newib.mainpage.SigningModalPage.LOADER_IMAGE_DIV_XPATH;

@Wait(value = {PAGE_LABEL_XPATH, PAGE_MODAL_SECTION_XPATH})
@Wait(value = LOADER_IMAGE_DIV_XPATH, until = Until.GONE)
public interface SigningModalPage extends NewIbPageFlow<SigningModalPage> {

    String PAGE_LABEL_XPATH = "//h1[text()=\"Smluvní dokumentace pro Vaše podnikání\"]";
    String PAGE_MODAL_SECTION_XPATH = "//section[@id='superModal']";
    String CONTINUE_TO_SIGN_BUTTON_XPATH = "//button[@data-testid='documentSignModal-sign-btn']";
    String LOADER_IMAGE_DIV_XPATH = "//svg[@class='c-loader__image']";
    String SIGN_BUTTON_XPATH = "//button[@data-testid='secondFactorSend']";
    String MOBILE_KEY_INPUT = "mobileKey";

    @Click(value = CONTINUE_TO_SIGN_BUTTON_XPATH, andWait = @Wait(value = LOADER_IMAGE_DIV_XPATH, until = Until.GONE))
    SigningModalPage clickContinueToSign();

    @TypeInto(value = MOBILE_KEY_INPUT, by = Lookup.ID)
    SigningModalPage fillMobKey(String mobKey);

    @Click(value = SIGN_BUTTON_XPATH, andWait = @Wait(value = LOADER_IMAGE_DIV_XPATH, until = Until.GONE))
    DashboardPage clickSign();

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