package cz.moneta.test.dsl.ufo.operations.shared.topmenu;

import cz.moneta.test.dsl.ufo.operations.client.clientDetail.STS701_S002_ClientDetailPage;
import cz.moneta.test.dsl.ufo.operations.client.product.KOK701_S001_MeetingSchedulingPage;
import cz.moneta.test.dsl.ufo.operations.recorder.CRC710_S001_RecorderMainPage;
import cz.moneta.test.dsl.ufo.operations.search.OPS001_S001_ClientSearchPageUfoOperations;
import cz.moneta.test.dsl.ufo.operations.shared.LogOutPage;
import cz.moneta.test.dsl.ufo.operations.ufoOperations.ETS701_S001_ClientDocuments;
import cz.moneta.test.dsl.ufo.operations.ufoOperations.KAL730_S001_CalculatorPage;
import cz.moneta.test.dsl.ufo.operations.ufoOperations.contactForwarding.XCM701_S001_ContactForwardingPage;
import cz.moneta.test.harness.context.StoreAccessor;
import cz.moneta.test.harness.endpoints.ufo.UfoEndpoint;
import cz.moneta.test.harness.support.web.*;
import org.junit.jupiter.api.Assertions;

import java.util.List;

import static cz.moneta.test.dsl.ufo.operations.shared.SharedElements.LOAD_IMG_DIV_CLASS;

public interface XXX702_SharedTopMenu<T extends WebFlow<T>> extends XXX702_SharedClientMenu<T>, XXX702_SharedSearchMenu<T>, StoreAccessor {

    String STATUS_BAR = "XXX702_T001_L107";

    String LOGOUT_BUTTON = "XXX702_T001_B008";

    String ACTUAL_DATE_DIV = "XXX702_T001_L172";

    String HOMEPAGE_BUTTON = "XXX702_T001_P007";
    String REFRESH_CLIENT_BUTTON = "XXX702_T001_P016";

    String CORRESPONDENCE_BUTTON = "XXX702_T001_P027";
    String MEETINGS_AND_SMS_BUTTON = "XXX702_T001_P028";
    String CONTACT_FORWARDING_BUTTON = "XXX702_T001_P018";
    String RECORDER_APP_BUTTON = "XXX702_T001_P024";
    String CALCULATOR_BUTTON = "XXX702_T001_P010";
    String TASK_MANAGEMENT_BUTTON = "XXX702_T001_P053";

    @GetElementContent(STATUS_BAR)
    String getStatusBarContent();

    @CheckElementContent(STATUS_BAR)
    T assertStatusBarContent(String expectedText);

    @CustomAction
    default T checkStatusBarIsEmpty() {
        String statusBarContent = getEndpoint(UfoEndpoint.class).getText(STATUS_BAR);
        Assertions.assertTrue(statusBarContent == null || statusBarContent.isEmpty(), "Expected status bar to be empty, but was: " + statusBarContent);
        return null;
    }


    @Click(LOGOUT_BUTTON)
    LogOutPage clickLogout();

    @GetElementContent(ACTUAL_DATE_DIV)
    String getActualDate();

    @Click(value = HOMEPAGE_BUTTON, andWait = @Wait(value = LOAD_IMG_DIV_CLASS, by = Lookup.CLASSNAME, until = Until.GONE))
    OPS001_S001_ClientSearchPageUfoOperations clickHomePage();

    @Click(REFRESH_CLIENT_BUTTON)
    T clickRefreshClientButton();

    @CustomAction
    default ETS701_S001_ClientDocuments clickCorrespondence() {
        UfoEndpoint endpoint = getEndpoint(UfoEndpoint.class);
        endpoint.click(() -> CORRESPONDENCE_BUTTON);
        endpoint.focusToNewPopup(10);
        return null;
    }

    @Click(MEETINGS_AND_SMS_BUTTON)
    KOK701_S001_MeetingSchedulingPage clickMeetingsAndSms();

    @Click(CONTACT_FORWARDING_BUTTON)
    XCM701_S001_ContactForwardingPage clickContactForwarding();

    @CustomAction
    default CRC710_S001_RecorderMainPage clickRecorder() {
        UfoEndpoint endpoint = getEndpoint(UfoEndpoint.class);
        endpoint.click(() -> RECORDER_APP_BUTTON);
        endpoint.focusToNewPopup(10);
        return null;
    }

    @Click(CALCULATOR_BUTTON)
    KAL730_S001_CalculatorPage clickCalculator();

    @CustomAction
    default STS701_S002_ClientDetailPage checkPageNotContainsMenuElements() {
        UfoEndpoint endpoint = getEndpoint(UfoEndpoint.class);
        List<String> elementsList = List.of(CORRESPONDENCE_BUTTON, MEETINGS_AND_SMS_BUTTON, CONTACT_FORWARDING_BUTTON, RECORDER_APP_BUTTON, CALCULATOR_BUTTON, TASK_MANAGEMENT_BUTTON);
        for (String element : elementsList) {
            Assertions.assertFalse(endpoint.isElementVisible(1, element, Lookup.ID));
        }
        return null;
    }

}
