package cz.moneta.test.dsl.brokerportal;

import cz.moneta.test.dsl.brokerportal.components.Menu;
import cz.moneta.test.harness.endpoints.hypos.BrokerPortalEndpoint;
import cz.moneta.test.harness.support.web.*;

import static cz.moneta.test.dsl.brokerportal.BrokerPortalHomePage.USER_PROFILE;

@Wait(USER_PROFILE)
public interface BrokerPortalHomePage extends WebFlow<BrokerPortalHomePage>, Menu {
    String USER_PROFILE = "//button[@id = 'userProfile']";
    String NEW_VERSION_MODAL_CLOSE_BUTTON = "//h4[contains(text(),'Nová verze')]/../preceding-sibling::header/button";

    @CheckElementPresent(USER_PROFILE)
    BrokerPortalHomePage checkPresentUserProfile();

    @CustomAction
    default BrokerPortalHomePage closeNewVersionModal() {
        BrokerPortalEndpoint endpoint = getEndpoint(BrokerPortalEndpoint.class);

        if (endpoint.isElementPresent(NEW_VERSION_MODAL_CLOSE_BUTTON, Lookup.XPATH)) {
            endpoint.click(() -> NEW_VERSION_MODAL_CLOSE_BUTTON);
        }
        return null;
    }
}