package cz.moneta.test.dsl.hypos.pages.cadaster;

import cz.moneta.test.dsl.hypos.enums.CadasterRequestType;
import cz.moneta.test.dsl.hypos.pages.HyposPageFlow;
import cz.moneta.test.harness.context.StoreAccessor;
import cz.moneta.test.harness.endpoints.hypos.HyposEndpoint;
import cz.moneta.test.harness.support.web.*;

import static cz.moneta.test.dsl.hypos.pages.cadaster.CadasterRequestPage.FILTER_TYPE_SELECT;

@Wait(FILTER_TYPE_SELECT)
public interface CadasterRequestPage extends HyposPageFlow<CadasterRequestPage>, StoreAccessor {
    String FILTER_TYPE_SELECT = "//select[@name='filter[type]']";
    String FILTER_STATUS_SELECT = "//select[@name='filter[status]']";
    String FILTER_SEARCH_BUTTON = "//button[text()='Zobrazit' and not(@disabled)]";
    String REDOC_DETAIL = "(//a[contains(@href,'redoc.overview')])[1]";

    @Click(value = FILTER_SEARCH_BUTTON, andWait = @Wait(value = REDOC_DETAIL, until = Until.CLICKABLE))
    CadasterRequestPage clickSearchButton();

    @Select(FILTER_TYPE_SELECT)
    CadasterRequestPage selectFilterType(CadasterRequestType type);

    @Select(FILTER_STATUS_SELECT)
    CadasterRequestPage selectFilterStatus(String status);

    @CustomAction
    default CadasterRedocDetailPage clickRedocDetail() {
        HyposEndpoint endpoint = getEndpoint(HyposEndpoint.class);
        endpoint.click(() -> REDOC_DETAIL);
        endpoint.switchToOtherWindow(20, 2);
        endpoint.maximizeBrowserWindow();
        return null;
    }
}