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

import cz.moneta.test.dsl.Harness;
import cz.moneta.test.dsl.payment_engine.PaymentEngineDetailAccountPage;
import cz.moneta.test.dsl.payment_engine.PaymentEngineReservationPage;
import cz.moneta.test.dsl.payment_engine.utils.PaymentEngineUtils;
import cz.moneta.test.harness.context.StoreAccessor;
import cz.moneta.test.harness.support.web.*;

import static cz.moneta.test.dsl.payment_engine.parts_of_menu.menu_cache24_7.PaymentsEngineCache24SearchAccountsNumber.INTERNAL_ACCOUNT_NUMBER;

@Wait(INTERNAL_ACCOUNT_NUMBER)
public interface PaymentsEngineCache24SearchAccountsNumber extends WebFlow<PaymentsEngineCache24SearchAccountsNumber>, StoreAccessor {
    String INTERNAL_ACCOUNT_NUMBER = "//input[@name='accIdent']";
    String APPLY_BUTTON = "//button[text()='Aplikovat']";
    String RESERVATION_BUTTON = "//a[text()='Blokace']//text()/../..";
    String DETAIL_BUTTON = "//a[text()='Detail']";
    String ACCOUNT_DETAIL = "//a[text()='Detail účtu']";
    String REFRESH_BUTTON = "//button[@class='x-btn-text x-tbar-loading']";

    @TypeInto(INTERNAL_ACCOUNT_NUMBER)
    @Click(value = APPLY_BUTTON, andWait = @Wait(value = INTERNAL_ACCOUNT_NUMBER, until = Until.VISIBLE, explicitWaitSeconds = 5))
    PaymentsEngineCache24SearchAccountsNumber typeInternalAccountNumberAndClickApply(String accountNumber);

    @Click(value = RESERVATION_BUTTON, andWait = @Wait(explicitWaitSeconds = 2))
    PaymentEngineReservationPage clickOnReservationButton();

    @Click(DETAIL_BUTTON)
    PaymentEngineDetailAccountPage clickOnDetail();

    @Click(ACCOUNT_DETAIL)
    PaymentEngineDetailAccountPage clickOnAccountDetail();

    @CustomAction
    default PaymentsEngineCache24SearchAccountsNumber waitForAccountState(Harness harness, String state) {
        PaymentEngineUtils.waitForElementPresence(harness, String.format("//*[contains(@class,'x-grid3-row-selected')]//div[contains(@class,'x-grid3-cell-inner x-grid3-col-9')][contains(text(),'%s')]", state), REFRESH_BUTTON);
        return null;
    }
}
