package cz.moneta.test.dsl.ufo.banka.pages.loans.expres;

import cz.moneta.test.dsl.ufo.banka.pages.loans.CAS001_S001_ScoringPage;
import cz.moneta.test.dsl.ufo.operations.shared.SharedElements;
import cz.moneta.test.harness.context.StoreAccessor;
import cz.moneta.test.harness.endpoints.ufo.UfoEndpoint;
import cz.moneta.test.harness.support.web.*;

import static cz.moneta.test.dsl.ufo.banka.pages.loans.expres.OPN008_S001_ExpressSignaturePage.PAGE_ID_XPATH;

@Wait(value = PAGE_ID_XPATH, by = Lookup.XPATH, waitSecondsForElement = 40)
public interface OPN008_S001_ExpressSignaturePage extends WebFlow<OPN008_S001_ExpressSignaturePage>, StoreAccessor, SharedElements {

    String PAGE_ID_XPATH = "//div[text()='OPN008_S001']";
    String APPLICANT_SIGNATURE_CHECKBOX = "OPN008_S001_G001-0";
    String YES_BUTTON = "OPN008_S001_B001";
    String CHECK_BUTTON = "OPN008_S001_B005";
    String CONFIRM_BUTTON = "OPN008_S001_B006";

    @Click(APPLICANT_SIGNATURE_CHECKBOX)
    OPN008_S001_ExpressSignaturePage clickApplicantCheckbox();

    @Click(value = YES_BUTTON,
            andWait = @Wait(value = LOAD_IMG_DIV_CLASS, by = Lookup.CLASSNAME, until = Until.GONE))
    OPN008_S001_ExpressSignaturePage clickYes();

    @CustomAction
    default OPN008_S001_ExpressSignaturePage clickYesAndDismissAlert() {
        UfoEndpoint endpoint = getEndpoint(UfoEndpoint.class);
        endpoint.click(() -> YES_BUTTON);
        endpoint.dismissAlert(40);
        endpoint.waitForElementsToLoad(40, Until.VISIBLE, CHECK_BUTTON);
        return null;
    }

    @Click(value = CHECK_BUTTON,
            andWait = @Wait(value = LOAD_IMG_DIV_CLASS, by = Lookup.CLASSNAME, until = Until.GONE))
    OPN008_S001_ExpressSignaturePage clickCheck();

    @Click(CONFIRM_BUTTON)
    CAS001_S001_ScoringPage clickContinue();

}
