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

import cz.moneta.test.dsl.brokerportal.contract.CalculatorPage;
import cz.moneta.test.dsl.brokerportal.contract.ContractListPage;
import cz.moneta.test.dsl.brokerportal.enums.Product;
import cz.moneta.test.dsl.brokerportal.userprofile.UserProfilePage;
import cz.moneta.test.harness.context.StoreAccessor;
import cz.moneta.test.harness.endpoints.hypos.BrokerPortalEndpoint;
import cz.moneta.test.harness.support.web.*;

import static cz.moneta.test.dsl.brokerportal.components.Menu.PRODUCTS_BUTTON;

@Wait(PRODUCTS_BUTTON)
public interface Menu extends StoreAccessor {
    String PRODUCTS_BUTTON = "//button[@id='products']";
    String PRODUCT_BUTTON = "//button[@id='%s']";
    String BUSINESSES_BUTTON = "//button[@id='businesses']";
    String NEW_VERSION_DISABLE = "//header[@class='c-modal__header']/button";
    String USER_PROFILE_BUTTON = "//button[@id='userProfile']";
    String USER_PROFILE_SETTINGS_BUTTON = "//button[@id='settings']";

    @Click(PRODUCTS_BUTTON)
    Menu clickProductsButton();

    @Click(PRODUCT_BUTTON)
    CalculatorPage clickProductMortgageButton(Product product);

    @Click(BUSINESSES_BUTTON)
    ContractListPage clickContracts();

    @Click(USER_PROFILE_BUTTON)
    Menu clickUserProfileButton();

    @Click(USER_PROFILE_SETTINGS_BUTTON)
    UserProfilePage clickUserProfileSettingsButton();

    /**
     * Clicking on X button on tab with new version available. This condition is here because this tab
     * is showing up only on local computer, not on server.
     * @return
     */
    @CustomAction
    default Menu disableNewVersion() {
        BrokerPortalEndpoint endpoint = getEndpoint(BrokerPortalEndpoint.class);

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