package cz.moneta.test.dsl.payment_engine.parts_of_menu.menu_transaction;

import cz.moneta.test.dsl.payment_engine.home.PaymentEngineHomePage;
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.parts_of_menu.menu_transaction.PaymentEngineDistributionToClearingArchiv.SEARCH_FIELD;


@Wait(SEARCH_FIELD)
public interface PaymentEngineDistributionToClearingArchiv extends WebFlow<PaymentEngineDistributionToClearingArchiv>, StoreAccessor {

    String AJAX_LOADING = "//div[text()='Načítám...']";
    String SEARCH_FIELD = "//input[@name='field1#id']";
    String SEARCH_BTN = "//button[@class='x-btn-text'][text() = 'Hledat']";
    String MANUAL_ACTIONS = "//a[text()= 'Manuální akce']";
    String CLOSE_TAB_BUTTON = "//a[@class='x-tab-strip-close']";
    String SEARCH_ID_BUTTON ="//em/button[@class='x-btn-text  grid-filter-collapse']";

    @Wait(value = SEARCH_FIELD, until = Until.VISIBLE)
    @TypeInto(SEARCH_FIELD)
    PaymentEngineDistributionToClearingArchiv fillId(String transactionId);

    @Click(value = SEARCH_BTN, andWait = @Wait(value = AJAX_LOADING, until = Until.GONE))
    PaymentEngineDistributionToClearingArchiv searchTransaction();

    @Wait(value = MANUAL_ACTIONS, until = Until.CLICKABLE)
    @Click(value = MANUAL_ACTIONS, andWait = @Wait(value = MANUAL_ACTIONS, until = Until.GONE))
    PaymentEngineDistributionToClearingArchiv clickOnManualActions();

    @Wait(value = MANUAL_ACTIONS, until = Until.GONE)
    PaymentEngineDistributionToClearingArchiv waitForManualActionsGone();


    @CustomAction
    default PaymentEngineDistributionToClearingArchivEdit clickManualActionsIfStillVisible() {
        PaymentEngineEndpoint paymentEngineEndpoint = getEndpoint(PaymentEngineEndpoint.class);
        if (paymentEngineEndpoint.isElementVisible(5, MANUAL_ACTIONS, Lookup.XPATH)) {
            clickOnManualActions().waitForManualActionsGone();
        }
        return null;
    }

    @Click(CLOSE_TAB_BUTTON)
    PaymentEngineHomePage closeTab();

}