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

import cz.moneta.test.harness.context.StoreAccessor;
import cz.moneta.test.harness.endpoints.ufo.UfoEndpoint;
import cz.moneta.test.harness.support.web.*;
import org.openqa.selenium.WebElement;

import java.util.List;

import static cz.moneta.test.dsl.ufo.banka.pages.loans.NEP028_S001_SignaturePage.PAGE_LABEL_XPATH;
import static cz.moneta.test.dsl.ufo.banka.pages.loans.NEP028_S001_SignaturePage.YES_BUTTON;

@Wait(value = PAGE_LABEL_XPATH, by = Lookup.XPATH, waitSecondsForElement = 40)
@Wait(value = YES_BUTTON, waitSecondsForElement = 40)
public interface NEP028_S001_SignaturePage extends WebFlow<NEP028_S001_SignaturePage>, StoreAccessor {

    String PAGE_LABEL_XPATH = "//div[text()='NEP028_S001']";
    String YES_BUTTON = "NEP028_S001_B001";
    String ALL_APPLICANT_CHECK_BOXES = "//input[contains(@id,'NEP028_S001_G001')]";
    String APPLICANT_CHECKBOX = "NEP028_S001_G001-0";
    String COAPPLICANT_CHECKBOX = "NEP028_S001_G001-1";

    @Click(APPLICANT_CHECKBOX)
    NEP028_S001_SignaturePage clickApplicantSignatureCheckbox();

    @Click(COAPPLICANT_CHECKBOX)
    NEP028_S001_SignaturePage clickCoApplicantSignatureCheckbox();

    @CustomAction
    default NEP028_S001_SignaturePage clickAllSignatureCheckboxes() {
        UfoEndpoint e = getEndpoint(UfoEndpoint.class);
        List<WebElement> applicantCheckboxes = e.findAndGetListOfElements(ALL_APPLICANT_CHECK_BOXES, Lookup.XPATH);
        for (WebElement applicantCheckbox : applicantCheckboxes){
            applicantCheckbox.click();
        }
        return null;
    }

    @Click(YES_BUTTON)
    NEP028_S001_SignaturePageTransitions clickYes();

}