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

import cz.moneta.test.dsl.Harness;
import cz.moneta.test.dsl.payment_engine.utils.PaymentEngineUtils;
import cz.moneta.test.harness.support.web.*;

public interface PaymentEngineClientsListOfClients extends WebFlow<PaymentEngineClientsListOfClients> {

    String CLIENT_ID = "//input[@name = 'ident']";
    String APPLY_BUTTON = "//button[text() = 'Aplikovat']";
    String REFRESH_BUTTON = "//button[@class = 'x-btn-text x-tbar-loading']";
    String CLIENT_NAME_KEY = "CLIENT_NAME_KEY";
    String CLIENT_NAME_XPATH = "//div[@class='x-grid3-cell-inner x-grid3-col-4']";
    String AJAX_LOADING = "//div[text()='Načítám...']";

    @Wait(value = CLIENT_ID, until = Until.VISIBLE)
    @TypeInto(CLIENT_ID)
    PaymentEngineClientsListOfClients fillClientId(String clientId);

    @Click(value = APPLY_BUTTON, andWait = @Wait(value = AJAX_LOADING, until = Until.GONE))
    PaymentEngineClientsListOfClients clickOnApply();

    @StoreElementContent(storeKey = CLIENT_NAME_KEY, value = CLIENT_NAME_XPATH, by = Lookup.XPATH)
    PaymentEngineClientsListOfClients storeClientName();

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

    @CustomAction
    default PaymentEngineClientsListOfClients waitForClientNameChange(Harness harness, String newClientName) {
        PaymentEngineUtils.waitForElementPresence(harness, String.format("//*[contains(@class,'x-grid3-row-selected')]//*[contains(text(),'%s')]", newClientName), REFRESH_BUTTON);
        return null;
    }
}
