package cz.moneta.test.dsl.forte.pages.contracts;

import cz.moneta.test.dsl.forte.FortePageFlow;
import cz.moneta.test.dsl.forte.components.ContractsMenu;
import cz.moneta.test.harness.support.web.*;

import static cz.moneta.test.dsl.forte.pages.contracts.FindContractsPage.*;

@Wait({PAGE_TITLE, CLEAR_BUTTON, SEARCH_BUTTON})
public interface FindContractsPage extends FortePageFlow<FindContractsPage>, ContractsMenu {
    String PAGE_TITLE = CONTENT_DIV + "//h3[text()='Hledat smlouvu']";
    String SEARCH_FORM = CONTENT_DIV + "//form[@id='frm-searchForm-searchForm']";
    String SEARCH_BY_SELECT = SEARCH_FORM + "//select[@name='search_type']";
    String CONTRACT_NUMBER_INPUT = SEARCH_FORM + "//input[@name='contract_num']";
    String CONTRACT_NAME_INPUT = SEARCH_FORM + "//input[@name='contract_name']";
    String CLEAR_BUTTON = SEARCH_FORM + "//input[@name='clear']";
    String SEARCH_BUTTON = SEARCH_FORM + "//input[@name='search']";

    String RESULT_FORM = CONTENT_DIV + "//form[@id='frm-grid-form']";
    String FIRST_RESULT_DETAIL_BUTTON = RESULT_FORM + "//span[@class='ge-icon fa icon icon-view ge-color-blue'][1]";

    @Select(SEARCH_BY_SELECT)
    FindContractsPage selectSearchBy(String searchBy);

    @TypeInto(CONTRACT_NUMBER_INPUT)
    FindContractsPage fillContractNumber(String contractNumber);

    @TypeInto(CONTRACT_NAME_INPUT)
    FindContractsPage fillContractName(String contractName);

    @Click(value = CLEAR_BUTTON, andWait = @Wait(value = SPINNER, until = Until.GONE, by = Lookup.ID))
    FindContractsPage clickClearForm();

    @Click(value = SEARCH_BUTTON, andWait = @Wait(value = SPINNER, until = Until.GONE, by = Lookup.ID))
    FindContractsPage clickSearchContract();

    @Click(FIRST_RESULT_DETAIL_BUTTON)
    ContractDetailPage clickFirstResultDetail();

}