package cz.moneta.test.dsl.ufo.banka.pages.cards.debit;

import cz.moneta.test.dsl.Harness;
import cz.moneta.test.dsl.ufo.banka.pages.fon.TIS050_S001_SignerSelectionPage;
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.cards.debit.PLK033_S001_ChangeMotoIntTransactions.PAGE_LABEL_XPATH;

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

    String PAGE_LABEL_XPATH = "//div[text()='PLK033_S001']";
    String INTERNET_ON_RADIO = "PLK033_S001_R002_1";
    String INTERNET_OFF_RADIO = "PLK033_S001_R002_0";
    String MOTO_ON_RADIO = "PLK033_S001_R001_1";
    String MOTO_OFF_RADIO = "PLK033_S001_R001_0";
    String DCC_ON_RADIO = "PLK033_S001_R003_1";
    String DCC_OFF_RADIO = "PLK033_S001_R003_0";
    String CHECKED_XPATH = "//input[@id='%s' and not(@checked)]";
    String CONTINUE_BUTTON = "PLK033_S001_B002";

    @CustomAction
    default PLK033_S001_ChangeMotoIntTransactions clickInternetAndMotoChange(Harness harness) {
        UfoEndpoint endpoint = getEndpoint(UfoEndpoint.class);
        if (endpoint.isElementPresent(String.format(CHECKED_XPATH, MOTO_ON_RADIO), Lookup.XPATH)) {
            endpoint.jsClick((() -> MOTO_ON_RADIO));
            endpoint.dismissAlert(1);
            endpoint.isElementPresent(String.format(CHECKED_XPATH, INTERNET_ON_RADIO), Lookup.XPATH);
            harness.store("MOTO_INFO", "MOTO/INT ON");
        } else {
            endpoint.jsClick((() -> MOTO_OFF_RADIO));
            endpoint.dismissAlert(1);
            endpoint.isElementPresent(String.format(CHECKED_XPATH, INTERNET_OFF_RADIO), Lookup.XPATH);
            harness.store("MOTO_INFO", "MOTO/INT OFF");
        }
        return null;
    }

    @CustomAction
    default PLK033_S001_ChangeMotoIntTransactions clickDccChange(Harness harness) {
        UfoEndpoint endpoint = getEndpoint(UfoEndpoint.class);
        if (endpoint.isElementPresent(String.format(CHECKED_XPATH, DCC_ON_RADIO), Lookup.XPATH)) {
            endpoint.jsClick((() -> DCC_ON_RADIO));
            harness.store("DCC_INFO", "DCC ON");
        } else {
            endpoint.jsClick((() -> DCC_OFF_RADIO));
            harness.store("DCC_INFO", "DCC OFF");
        }
        return null;
    }

    @Click(value = CONTINUE_BUTTON)
    PSP004_S001_PrintPage clickToPrint();

    @Click(value = CONTINUE_BUTTON)
    TIS050_S001_SignerSelectionPage clickToSignerSelectionPage();
}
