package cz.moneta.test.dsl.hypos.components;

import cz.moneta.test.dsl.hypos.pages.contract.ContractHistoryPage;
import cz.moneta.test.harness.context.StoreAccessor;
import cz.moneta.test.harness.support.web.Builder;
import cz.moneta.test.harness.support.web.CheckElementPresent;
import cz.moneta.test.harness.support.web.Click;
import cz.moneta.test.harness.support.web.Until;
import cz.moneta.test.harness.support.web.Wait;

import static cz.moneta.test.dsl.hypos.components.ContractMenu.EVENTS_STATE_BOX_LINK;
import static cz.moneta.test.dsl.hypos.components.ContractMenu.SET_EVENTS_FLAGS_LINK;
import static cz.moneta.test.dsl.hypos.pages.HyposPageFlow.LOADER;

@Wait({EVENTS_STATE_BOX_LINK, SET_EVENTS_FLAGS_LINK})
public interface ContractMenu extends Builder, StoreAccessor {
    //Menu below horizontal main menu on contract pages
    String CONTRACT_MENU_DIV = "//div[@id='info-tab-block']";
    String CONTRACT_STATE_TD = CONTRACT_MENU_DIV + "//table[@id='listicka-radek-tbl-2']//td[contains(text(),'%s')]";
    String EVENTS_STATE_BOX_LINK = CONTRACT_MENU_DIV + "//a[contains(text(),'přejít')]";
    String SET_EVENTS_FLAGS_LINK = CONTRACT_MENU_DIV + "//a[contains(text(),'nastavit příznak')]";

    String EVENTS_STATE_BOX_DIV = CONTRACT_MENU_DIV + "//div[@id='events-state-box']";
    String EVENTS_STATE_PREPARE_CONTRACTS_LINK = EVENTS_STATE_BOX_DIV + "//a[contains(text(),'Příprava smluv')]";

    String EVENTS_SET_FLAGS_DIV = CONTRACT_MENU_DIV + "//div[@id='events-set-flags']";
    String EVENT_FLAG_LINK = EVENTS_SET_FLAGS_DIV + "//a[contains(text(),'%s')]";

    String COMMENT_BOX_SAVE_BUTTON = CONTRACT_MENU_DIV + "//div[@id='CommentBox' and contains(@style,'display: block')]//input[@value='Uložit']";

    @CheckElementPresent(value = CONTRACT_STATE_TD, isStringDynamicXpath = true)
    ContractHistoryPage checkContractState(String state);

    @Click(SET_EVENTS_FLAGS_LINK)
    ContractHistoryPage clickSetEventsFlagsLink();

    @Click(EVENTS_STATE_BOX_LINK)
    ContractHistoryPage clickEventsStateBoxLink();

    @Wait(EVENTS_STATE_PREPARE_CONTRACTS_LINK)
    @Click(EVENTS_STATE_PREPARE_CONTRACTS_LINK)
    ContractHistoryPage clickPrepareContractsStateLink();

    @Click(value = EVENT_FLAG_LINK, andWait = @Wait(value = LOADER, until = Until.GONE), isStringDynamicXpath = true)
    ContractHistoryPage clickContractFlag(String contractFlag);

    @Click(value = COMMENT_BOX_SAVE_BUTTON, andWait = @Wait(value = LOADER, until = Until.GONE))
    ContractHistoryPage clickCommentBoxSaveButton();
}