package cz.moneta.test.dsl.ib.account.saving;

import cz.moneta.test.dsl.ib.IbPageFlow;
import cz.moneta.test.dsl.ib.components.MainMenu;
import cz.moneta.test.dsl.ib.components.SavingMenu;
import cz.moneta.test.harness.support.web.*;

import static cz.moneta.test.dsl.ib.account.saving.TransferOfFoundsEnteringPage.*;

@Wait({PAGE_ID, IMG_NAME_OF_PAGE, FIRST_STEP_IN_PROGRESS_IMG, TABLE_TRANSFER_XPATH, TRANSFER_TO_SAVING_ACCOUNT_XPATH})
public interface TransferOfFoundsEnteringPage extends IbPageFlow<TransferOfFoundsMainPage>, MainMenu, SavingMenu {
    String PAGE_ID = "//div[@id='parentform']";
    String IMG_NAME_OF_PAGE = "//img[@alt='Převod prostředků']";
    String FIRST_STEP_IN_PROGRESS_IMG = PAGE_ID + "//img[@src='images_new/top_step1.gif']";
    String TABLE_TRANSFER_XPATH = "//table[@id='tableTransfer']";
    String TRANSFER_TO_SAVING_ACCOUNT_XPATH = TABLE_TRANSFER_XPATH + "//td[contains(text(),'Převod')]/following::input[@id='transferType']/following-sibling::span[contains(text(),'Na spořicí účet')]";
    String INPUT_AMOUNT = PAGE_ID + "//td[contains(text(), 'Částka')]//parent::td//following::input[@id='amount']";
    String CONTINUE_BUTTON = "//img[@alt='Pokračovat']";

    //Table - Transfer to saving account
    String TRANSFER_TO_SAVING_ACCOUNT_TABLE = "//table[@id='transfer.toSavingAccount']";
    String FROM_ACCOUNT_XPATH = TRANSFER_TO_SAVING_ACCOUNT_TABLE + "//td[contains(text(), 'Z účtu')]/following-sibling::td//select[@id='fromAccount']";
    String DISPO_CURRENT_ACCOUNT_XPATH = TRANSFER_TO_SAVING_ACCOUNT_TABLE + "//tr[@id='_tr_dispoBalance2']/td[text()='Disponibilní zůstatek']";
    String DUE_DATE = "//td[text()='Datum splatnosti']/following::input[@id='valueDateToSavingAcc']";

    //Transfer from saving account
    String TRNSFER_TO_MONETA_XPATH = "//td[contains(text(),'Převod na')]//following::input[@id='transferTo']/following-sibling::span[text()='Vlastní účet v MONETA Money Bank']";
    String TO_ACCOUNT_XPATH = "//span[contains(text(), 'Ze spořicího účtu')]//preceding-sibling::input[@id='transferType']";
    String SELECT_ACCOUNT = "//td[contains(text(),'Na účet')]//following::select[@id='toAccount']";

    @TypeInto(INPUT_AMOUNT)
    TransferOfFoundsEnteringPage inputAmountToTransfer(String amountToTransfer);

    @CheckElementsPresent({
            @CheckElementPresent(value = FROM_ACCOUNT_XPATH),
            @CheckElementPresent(value = DISPO_CURRENT_ACCOUNT_XPATH),
            @CheckElementPresent(value = DUE_DATE)
    })
    TransferOfFoundsEnteringPage checkElementsTransferToSavingAccount();

    @Click(CONTINUE_BUTTON)
    TransferOfFoundsCheckPage clickToContinueButton();

    @Click(TO_ACCOUNT_XPATH)
    TransferOfFoundsEnteringPage chooseTransferFromSavingAccount();

    @CheckElementsPresent({
            @CheckElementPresent(value = TRNSFER_TO_MONETA_XPATH),
            @CheckElementPresent(value = SELECT_ACCOUNT),
            @CheckElementPresent(value = DUE_DATE)
    })
    TransferOfFoundsEnteringPage checkElementsTransferFromSavingAccount();
}
