package cz.moneta.test.dsl.ib.accountsandtransactions.paymentordershistory;

import cz.moneta.test.dsl.ib.IbPageFlow;
import cz.moneta.test.dsl.ib.components.MainMenu;
import cz.moneta.test.dsl.ib.welcome.WelcomePage;
import cz.moneta.test.harness.context.StoreAccessor;
import cz.moneta.test.harness.endpoints.ib.IbEndpoint;
import cz.moneta.test.harness.support.web.*;

import static cz.moneta.test.dsl.ib.accountsandtransactions.paymentordershistory.PaymentOrdersHistoryPage.PAGE_TITLE;

@Wait(PAGE_TITLE)
public interface PaymentOrdersHistoryPage extends IbPageFlow<WelcomePage>, MainMenu, StoreAccessor {
    String PAGE_TITLE = "//table[@id='titleLabelTable']//img[@alt='Přehled příkazů k úhradě zadaných on-line kanály']";
    String DISPLAY_BUTTON = "//table[@id='helpNav']//img[contains(@src, 'images_new/zobrazit_b.gif')]";
    String TRANSACTIONS_TYPES = "//table[@id='helpNav']//select[@id='typPrikazuDatas']";
    String TRANSACTIONS_ID_ORDER = "//a[contains(text(), 'ID transakce ')]/img";
    String TRANSACTIONS_PACKAGE_ID_XPATH = "//tr[@id='a1']/td[5]";
    String DATE_FROM = "//input[@id='valueDateFrom']";
    String LOADER_DIV = "//div[@class='busyLoader']";

    @Click(value = DISPLAY_BUTTON, andWait = @Wait(value = LOADER_DIV, until = Until.GONE))
    PaymentOrdersHistoryPage clickDisplayTransactions();

    @Click(value = TRANSACTIONS_ID_ORDER, andWait = @Wait(value = LOADER_DIV, until = Until.GONE))
    PaymentOrdersHistoryPage clickOrderTransactionsById();

    @TypeInto(value = DATE_FROM, clear = true)
    PaymentOrdersHistoryPage fillDateFrom(String actualDate);

    @Select(TRANSACTIONS_TYPES)
    PaymentOrdersHistoryPage selectTransactionsTypes(String transactionTypes);

    @GetElementContent(TRANSACTIONS_PACKAGE_ID_XPATH)
    String getElementWithPackageId();

    @CustomAction()
    default PaymentOrdersHistoryPage checkElementContentPackageId(String packageId) {
        log("Data from IB:\n" + getElementWithPackageId());
        IbEndpoint endpoint = getEndpoint(IbEndpoint.class);
        endpoint.checkElementContent(TRANSACTIONS_PACKAGE_ID_XPATH, packageId);
        return null;
    }
}