package cz.moneta.test.dsl.payment_engine;

import cz.moneta.test.dsl.payment_engine.parts_of_menu.menu_transaction.PaymentEngineDistributionToClearingArchiv;
import cz.moneta.test.dsl.payment_engine.parts_of_menu.menu_transaction.PaymentEngineManualForVerificationPage;
import cz.moneta.test.harness.context.StoreAccessor;
import cz.moneta.test.harness.endpoints.payment_engine.PaymentEngineEndpoint;
import cz.moneta.test.harness.support.web.*;

import static cz.moneta.test.dsl.payment_engine.PaymentEngineForeignPaymentDetailPage.SUBMIT_BUTTON;

@Wait(SUBMIT_BUTTON)
public interface PaymentEngineForeignPaymentDetailPage extends WebFlow<PaymentEngineForeignPaymentDetailPage>, StoreAccessor {

    String AJAX_LOADING = "//div[text()='Načítám...']";
    String SUBMIT_BUTTON = "//button[text() = 'OK']";

    @Wait(value = SUBMIT_BUTTON, until = Until.CLICKABLE)
    @Click(value = SUBMIT_BUTTON, jsClick = true)
    PaymentEngineForeignPaymentDetailPage clickSubmit();

    @Wait(value = AJAX_LOADING, until = Until.GONE)
    PaymentEngineDistributionToClearingArchiv waitForAjax();

    @CustomAction
    default PaymentEngineManualForVerificationPage clickSubmitIfStillVisible() {
        PaymentEngineEndpoint endpoint = getEndpoint(PaymentEngineEndpoint.class);
        if (!endpoint.isElementVisible(5, PaymentEngineManualForVerificationPage.SEARCH_ID_BUTTON, Lookup.XPATH)) {
            clickSubmit().waitForAjax();
        }
        return null;
    }
}