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

import cz.moneta.test.dsl.ufo.banka.pages.main.PSP004_S001_PrintPage;
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.fon.TIS050_S001_SignerSelectionPage.CONTINUE_BUTTON;

@Wait(value = {CONTINUE_BUTTON}, waitSecondsForElement = 60)
public interface TIS050_S001_SignerSelectionPage extends WebFlow<TIS050_S001_SignerSelectionPage>, StoreAccessor {

    String CONTINUE_BUTTON = "TIS050_S001_B001";
    String SIGNED_PERSONALLY_RADIO = "TIS050_S001_R003_0";
    String PHYSICAL_SIGNATURE_RADIO = "TIS050_S001_R001_3";
    String PHYSICAL_SIGNATURE_LABEL = "TIS050_S001_L011";

    @Click(value = SIGNED_PERSONALLY_RADIO, jsClick = true)
    @Click(value = PHYSICAL_SIGNATURE_RADIO, jsClick = true)
    @Click(CONTINUE_BUTTON)
    TIS050_S001_SignerSelectionPageTransitions clickSignedPersonallyPhysicallyAndContinue();

    @Click(value = SIGNED_PERSONALLY_RADIO, jsClick = true)
    @Click(CONTINUE_BUTTON)
    PSP004_S001_PrintPage clickSignedPersonallyAndContinue();

    @Click(value = SIGNED_PERSONALLY_RADIO, jsClick = true)
    @Click(value = PHYSICAL_SIGNATURE_RADIO, jsClick = true)
    @Click(CONTINUE_BUTTON)
    PSP004_S001_PrintPage clickSignedAndContinueToPrintPage();

    @CustomAction
    default TIS050_S001_SignerSelectionPageTransitions clickSignedPersonallyWithPossiblePhysicalSignature(){
        UfoEndpoint endpoint = getEndpoint(UfoEndpoint.class);
        endpoint.jsClick(() -> SIGNED_PERSONALLY_RADIO);
        if (endpoint.isElementVisible(2, PHYSICAL_SIGNATURE_LABEL, Lookup.ID)) {
            endpoint.jsClick(() -> PHYSICAL_SIGNATURE_RADIO);
        }
        endpoint.click(() -> CONTINUE_BUTTON);
        return null;
    }
}
