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

import cz.moneta.test.dsl.forte.FortePageFlow;
import cz.moneta.test.harness.context.StoreAccessor;
import cz.moneta.test.harness.endpoints.forte.ForteEndpoint;
import cz.moneta.test.harness.support.web.*;

import static cz.moneta.test.dsl.forte.components.RoleSelection.ROLE_MENU;

@Wait(ROLE_MENU)
public interface RoleSelection<T> extends Builder, StoreAccessor {
    String LEFT_PANEL = "//div[@class='side-block']";
    String ROLE_MENU = LEFT_PANEL + "//select[@id='frmroleForm-role']";
    String MAIN_CATEGORY = LEFT_PANEL + "//a[starts-with(text(), 'Úvod')]";

    @CustomAction
    default T selectRoleMenu(ForteRoles valueRole) {
        ForteEndpoint endpoint = getEndpoint(ForteEndpoint.class);
        endpoint.selectByVisibleText(ROLE_MENU, valueRole.getValue());
        endpoint.waitForElementsToLoad(10, Lookup.ID, Until.GONE, FortePageFlow.SPINNER);
        endpoint.click(() -> MAIN_CATEGORY);
        endpoint.waitForElementsToLoad(10, Lookup.ID, Until.GONE, FortePageFlow.SPINNER);
        return null;
    }

}
